How to pass argument to script which is input to bash

6,273

Solution 1

I believe what you are looking for is the -s option. With -s, you can pass arguments to the script.

As a dummy example to illustrate this:

$ echo 'echo 1=$1' | bash -s -- Print
1=Print

Here, you can see that the script provided on stdin is given the positional parameter Print. Your script takes a -u UUID argument and that can be accommodated also:

$ echo 'echo arguments=$*' | bash -s -- -u UUID print
arguments=-u UUID print

So, in your case:

curl -fsSL http://git.io/vvZMn | bash -s -- print

Or,

curl -fsSL http://git.io/vvZMn | bash -s -- -u UUID print

As Stephen Harris pointed out, downloading a script and executing it, sight unseen, is a security concern.

Solution 2

If your system has /dev/stdin, you can use

$ echo 'echo 1=$1' | bash /dev/stdin print
1=print

Do not do this:

$ echo 'echo 1=$1' | bash /dev/stdin -- print
1=--

If you want to use --, do this:

$ echo 'echo 1=$1' | bash -- /dev/stdin print
1=print
Share:
6,273

Related videos on Youtube

k06a
Author by

k06a

Updated on September 18, 2022

Comments

  • k06a
    k06a over 1 year

    Right now I have one-liner like this:

    curl -fsSL http://git.io/vvZMn | bash
    

    It is downloading script and passing it to bash as stdin file. I would like to run this script with additional argument print.

    Maybe something like this?

    curl -fsSL http://git.io/vvZMn | bash -- print
    

    But this doesn't work.

    • Stephen Harris
      Stephen Harris over 7 years
      What are you expecting print to do here? Display the commands being run? If so, try bash -x. Note: this curl | bash routine is a massive security hole; you don't get the see what will be run until your server has been pwned.