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

前端 未结 2 632
天涯浪人
天涯浪人 2021-01-31 14:40

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         


        
相关标签:
2条回答
  • 2021-01-31 15:13

    After @ccarton's comment:

    cat script.sh | bash -s - arguments
    

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

    0 讨论(0)
  • 2021-01-31 15:22

    On Linux,

    cat script.sh | bash /dev/stdin arguments
    

    seems to work.

    0 讨论(0)
提交回复
热议问题