what is the role of "bash -s"?

I see following line to install chefdk

curl -L https://chef.io/chef/install.sh | sudo bash -s -- -P chefdk

Open in new window


I want to understand that does "bash -s -- -P chefdk" does and how does '-P' gets supplied as option to 'install.sh' and not to 'bash' ?
beer9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
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.
...
       --        A -- signals the end of options and disables further option processing.  Any arguments after the -- are treated as filenames and  arguments.   An  argument  of  -  is
                 equivalent to --.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
woolmilkporcCommented:
-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.
0
tel2Commented:
Hi woolmilkporc,

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

Does this mean that after running that whole one-liner, the 1st & 2nd "words" (for lack of a better word) of the output of the curl command will be accessible via $1 & $2?

Also, any ideas why "sudo" is being used here?  Does it imply the user doesn't even have access to run bash without sudo?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ozoCommented:
Does this mean that after running that whole one-liner, the 1st & 2nd "words" (for lack of a better word) of the output of the curl command will be accessible via $1 & $2?
No
Also, any ideas why "sudo" is being used here?
Perhaps so that the commands in https://chef.io/chef/install.sh can be run as root
Does it imply the user doesn't even have access to run bash without sudo?
No
0
woolmilkporcCommented:
The curl command will download a script ("install.sh") and the bash command will execute it on the fly. "-P" and "chefdk" will be presented to this script as if they had been specified on the command line of "install.sh".

It's just the same as if you downloaded "install.sh" and ran it like:

install.sh -P chefdk

Let's make an easy example. Assume that the code of "install.sh" would consist of just two statements to print out the commandline parameters: 'echo $1' and 'echo $2'. Feeding this to the bash statement in question:

echo 'echo $1; echo $2' | bash -s -- -P chefdk

will result in

-P
chefdk


being displayed.

"sudo" is certainly used because the "install.sh" code contains commands which must be run with root privileges or because it reads/writes from/to files/directories which only root can access.
The user can well run bash without sudo, but for the above reasons a bash started with root privileges is required.

Note: The script install.sh will most probably run something like "getopts" to parse its options and their arguments, so the variables "$1" and "$2" will not necessarily be used - although the script could use them, their content will be as described.
0
tel2Commented:
Thanks ozo for a concise answer, as usual.

And thanks even more for a well explained answer, woolmilkpork.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.