Run a script piped from stdin (Linux/Shell Scripting)

Just pipe it to your favorite shell, for example:

$ cat my_script.sh
set -x
echo hello
$ cat my_script.sh | sh
+ echo hello
hello

(The set -x makes the shell print out each statement it is about to run before it runs it, handy for debugging, but it has nothing to do with your issue specifically - just there for demo purposes.)


You could use stdin from pipe:

cat my_script.sh | xargs -i <some_command> {}

or:

cat my_script.sh | bash -

or (just from stdin):

bash < my_script.sh