Passing parameters to bash when executing a script fetched by curl

Daniel R picture Daniel R · Jan 10, 2011 · Viewed 27.3k times · Source

I know how to execute remote Bash scripts like this:

curl http://example.com/script.sh | bash

or

bash < <( curl http://example.com/script.sh )

which give the same result.

But what if I need to pass arguments to the bash script? It's possible when the script is saved locally:

./script.sh argument1 argument2

I tried several possibilities like this one, without success:

bash < <( curl http://example.com/script.sh ) argument1 argument2

Answer

jinowolski picture jinowolski · Jan 10, 2011

try

curl http://foo.com/script.sh | bash -s arg1 arg2

bash manual says:

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.