bash: Pass arguments but read script from stdin
You can use /dev/stdin
to read the bash script from stdin
but still pass command line arguments:
cat myscript.sh | bash /dev/stdin arg1 arg2 # ...
This is especially useful when directly piping scripts from wget
or curl
. Example:
wget https://example.com/script.sh | bash /dev/stdin arg