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:

bash_pass_arguments_stdin_example.sh
cat myscript.sh | bash /dev/stdin arg1 arg2 # ...

This is especially useful when directly piping scripts from wget or curl. Example:

bash_pass_arguments_stdin_example.sh
wget https://example.com/script.sh | bash /dev/stdin arg

 

 


Check out similar posts by category: Shell