我是bash的新手,并试图了解下面的脚本正在做什么,我知道-e
已退出,但我不确定-se
是什么或{{1} 1}}是为了?
$delimiter
答案 0 :(得分:9)
来自man bash
:
-s If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell.
来自help set
:
-e Exit immediately if a command exits with a non-zero status.
因此,这告诉bash从标准输入读取要执行的脚本,并且如果脚本中的任何命令(来自stdin)失败,则立即退出。
分隔符用于标记脚本的开头和结尾。这称为Here Document或heredoc。
答案 1 :(得分:1)
-s
选项通常与curl $script_url | bash
模式一起使用。例如,
curl -L https://chef.io/chef/install.sh | sudo bash -s -- -P chefdk
-s
使bash从stdin读取命令(“ curl”下载的“ install.sh”代码),并且仍然接受位置参数。
--
使bash将后面的所有内容都视为位置参数而不是选项。
bash会将“ install.sh”代码的变量$1
和$2
分别设置为-P
和chefdk
。
参考:https://www.experts-exchange.com/questions/28671064/what-is-the-role-of-bash-s.html