user2834482
user2834482

Reputation: 487

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?

$delimiter = 'EOF-MY-APP';

$process = new SSH(
    "ssh $target 'bash -se' << \\$delimiter".PHP_EOL
        .'set -e'.PHP_EOL
        .$command.PHP_EOL
        .$delimiter
);

Upvotes: 20

Views: 54413

Answers (2)

Broken Pipe
Broken Pipe

Reputation: 2981

The -s options is usually used along with the curl $script_url | bash pattern. 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.

-- lets bash treat everything which follows as positional parameters instead of options.

bash will set the variables $1 and $2 of the "install.sh" code to -P and to chefdk, respectively.

Reference: https://www.experts-exchange.com/questions/28671064/what-is-the-role-of-bash-s.html

Upvotes: 26

Will
Will

Reputation: 24699

From 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:

 -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.

The delimiter is used to mark the start and end of the script. This is called a Here Document or a heredoc.

Upvotes: 20

Related Questions