I'm running a bash script using
wget -O - https://myserver/install/Setup.sh | bash
How can I pass a parameter to the above script so it runs? something like
wget -O - https://myserver/install/Setup.sh parameter1 | bash
The standard format for the bash
(or sh
or similar) command is bash scriptfilename arg1 arg2 ...
. If you leave off all the first argument (the name or path of the script to run), it reads the script from stdin. Unfortunately, there's no way to leave off the firs argument but pass the others. Fortunately, you can pass /dev/stdin
as the first argument and get the same effect (at least on most unix systems):
wget -O - https://myserver/install/Setup.sh | bash /dev/stdin parameter1
If you're on a system that doesn't have /dev/stdin, you might have to look around for an alternative way to specify stdin explicitly (/dev/fd/0 or something like that).
Edit: Léa Gris suggestion of bash -s arg1 arg2 ...
is probably a better way to do this.