简体   繁体   English

bash -s做什么?

[英]What does bash -s do?

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
);

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. 

From help set : 来自help set

  -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读取要从Standard Input执行的脚本,并且如果脚本中的任何命令(来自stdin)失败,则立即退出。

The delimiter is used to mark the start and end of the script. 分隔符用于标记脚本的开头和结尾。 This is called a Here Document or a heredoc. 这称为Here Document或heredoc。

The -s options is usually used along with the curl $script_url | bash -s选项通常与curl $script_url | bash一起使用 curl $script_url | bash pattern. curl $script_url | bash模式。 For example, 例如,

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从stdin生成bash读命令(“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会将“install.sh”代码的变量$1$2分别设置为-Pchefdk

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM