bash -s 有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37224634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does bash -s do?
提问by user2834482
I'm new to bash and trying to understand what the script below is doing, i know -e
is exit but i'm not sure what -se
or what the $delimiter
is for?
我是 bash 的新手,并试图了解下面的脚本在做什么,我知道-e
是退出,但我不确定它是什么-se
或$delimiter
用于什么?
$delimiter = 'EOF-MY-APP';
$process = new SSH(
"ssh $target 'bash -se' << \$delimiter".PHP_EOL
.'set -e'.PHP_EOL
.$command.PHP_EOL
.$delimiter
);
回答by Will
From man bash
:
来自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.
-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.
From help set
:
来自help set
:
-e Exit immediately if a command exits with a non-zero status.
-e Exit immediately if a command exits with a non-zero status.
So, this tells bash to read the script to execute from Standard Input, and to exit immediately if any command in the script (from stdin) fails.
因此,这告诉 bash 读取脚本以从标准输入执行,并在脚本中的任何命令(来自 stdin)失败时立即退出。
The delimiter is used to mark the start and end of the script. This is called a Here Documentor a heredoc.
分隔符用于标记脚本的开始和结束。这称为Here Document或 heredoc。
回答by navigaid
The -s
options is usually used along with the curl $script_url | bash
pattern. For example,
这些-s
选项通常与curl $script_url | bash
模式一起使用。例如,
curl -L https://chef.io/chef/install.sh | sudo bash -s -- -P chefdk
-s
makes bash read commands (the "install.sh" code as downloaded by "curl") from stdin, and accept positional parameters nonetheless.
-s
使 bash 从 stdin 读取命令(由“curl”下载的“install.sh”代码),并接受位置参数。
--
lets bash treat everything which follows as positional parameters instead of options.
--
让 bash 将后面的所有内容视为位置参数而不是选项。
bash will set the variables $1
and $2
of the "install.sh" code to -P
and to chefdk
, respectively.
bash 将变量$1
和$2
“install.sh”代码分别设置为-P
和chefdk
。
Reference: https://www.experts-exchange.com/questions/28671064/what-is-the-role-of-bash-s.html
参考:https: //www.experts-exchange.com/questions/28671064/what-is-the-role-of-bash-s.html