Pass args for script when going thru pipe

You can pass arguments to the shell using the -s option:

cat script | bash -s 5

Use bash -s -- <args>

e.g, install google cloud sdk

~ curl https://sdk.cloud.google.com | bash -s -- --disable-prompts


cat script | sh -s -- 5

The -s argument tells sh to take commands from standard input and not to require a filename as a positional argument. (Otherwise, without -s, the next non-flag argument would be treated as a filename.)

The -- tells sh to stop processing further arguments so that they are only picked up by the script (rather than applying to sh itself). This is useful in situations where you need to pass a flag to your script that begins with - or -- (e.g.: --dry-run) that must be ignored by sh. Also note that a single - is equivalent to --.

cat script | sh -s - --dry-run