My question is similar to Wget a script and run it but i want to additionally pass some parameters to the script. Is it possible to do?

1 Answer 1


This should work

wget -qO - http://example.com/script.sh | bash -s param1 param2 ...

According to man BASH(1).

If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell or when reading input through a pipe

You can try it with a test file

$ cat script.sh
#!/usr/bin/env bash

echo "$@"
$ python3 -m http.server 1234

And from another shell

$ wget -qO - http://localhost:1234/script.sh | bash -s param1 param2 ...
param1 param2 param3 ...

Make sure to stop the local http server afterward.

EDIT: updating the answer based on @Gordon Davisson's comment.

  • 1
    bash $0 param1 param2 will generally work, but mostly by accident. In a normal interactive bash shell, $0 will expand to "-bash". bash -bash runs bash with the options -b, -a, -s, and -h. -s is actually the thing you want here -- it basically tells bash to run commands from standard input, and pass the remaining args to the script. The other options, -b, -a, and -h, are irrelevant and mostly harmless. But as I said, it's mostly by accident that this works; you really should just use bash -s param1 param2. Jan 22, 2021 at 4:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .