0

I have written a shell script to configure a development environment and and retrieving using cURL. The script takes up to 3 flags, -d, -f and -s.

How do I pass the flags to the shell script?

Here is the command to run the bash script:

$ curl -sL https://example.com/setup.sh | bash

Here is my first (failed) attempt to pass flags to the script:

$ curl -sL https://example.com/setup.sh | bash -dfs
  bash: -d: invalid option

Can anyone explain how to do this?

Mark Tyers
  • 2,961
  • 4
  • 29
  • 52
  • try adding `--` to signal the end of bash arguments and the start of command arguments: `curl -sL https://example.com/setup.sh | bash -- -dfs` – joshmeranda May 31 '22 at 13:20
  • @joshmeranda, that causes bash to treat `-dfs` as a filename to execute (that being the default way the first non-option argument is parsed). – Charles Duffy May 31 '22 at 13:21
  • Possibly duplicate of [Pass args for script when going thru pipe](https://stackoverflow.com/q/14693100/7939871) – Léa Gris May 31 '22 at 13:56

1 Answers1

2

Use the -s argument:

curl -sL https://example.com/setup.sh | bash -s -- -dfs
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441