简体   繁体   中英

Bash - How to pass arguments to a script that is read via standard input

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

On Linux,

cat script.sh | bash /dev/stdin arguments

seems to work.

After @ccarton's comment :

cat script.sh | bash -s - arguments

It's more portable than @Michael Hoffman's solution .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM