Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
);
like image 440
user2834482 Avatar asked May 14 '16 08:05

user2834482


2 Answers

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.

like image 59
Will Avatar answered Oct 05 '22 04:10

Will


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

like image 31
navigaid Avatar answered Oct 05 '22 05:10

navigaid