Bash: Passing Arguments Through Curl

In this quick guide I will show you how to pass arguments to scripts while using curl. Sometimes you may have a script that you wish to curl multiple times or on multiple servers but also need to pass arguments to them. Rather than wget, chmod, and then execute, you can curl and pipe said script directly into bash with one command. Here are 2 quick and easy methods to do so.

Method 1:

This first method will curl a script and pipe it directly into bash while also passing along any arguments we add. To do this we will add a -s argument to bash before adding our actual arguments. Here is an example of this method in use.

curl -s | bash -s argument1 argument2 argument3

Method 2:

An alternative is to use bash redirection and add the arguments to the end just as you would if you were running the script locally. Here is an example of this method in practice.

bash <(curl -s argument1 argument2 argument3

I hope this quick and easy guide helped you out, please show some love by liking, commenting, or sharing this post using the social media buttons below. Thank you!

Leave a Reply

Protected with IP Blacklist CloudIP Blacklist Cloud