Reputation: 2502
I am trying execute a script from standard input and also pass arguments to it. Is there a way to do it?
Let's say that I have the following:
cat script.sh | bash
How would I pass the arguments to the script?
I do not want to do this:
bash script.sh arguments
Nor this:
./script.sh arguments
Upvotes: 58
Views: 15139
Reputation: 6340
After @ccarton's comment:
cat script.sh | bash -s - arguments
It's more portable than @Michael Hoffman's solution.
Upvotes: 44
Reputation: 34324
On Linux,
cat script.sh | bash /dev/stdin arguments
seems to work.
Upvotes: 57