I download some shell script from example.com with wget
and execute it immediately by streaming stdout of wget
via a pipe to stdin of the sh
command.
wget -O - http://example.com/myscript.sh | sh -
How can I pass arguments to the script?
You need to use -s
option while invoking bash
for passing an argument to the shell script being downloaded:
wget -O - http://example.com/myscript.sh | bash -s 'arg1' 'arg2'
As per 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.
While the accepted answer is correct, it does only work on bash
and not on sh
as the initial poster requested.
To do this in sh
you'll have to add --
:
curl https://example.com/script.sh | sh -s -- --my-arg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With