Tony Sparker
Tony Sparker

Reputation: 33

How to pass a parameter to a downloaded script

I'm stuck passing a parameter(URL to download) to a script.

My goal is to create a script for deployment that downloads and installs an app. The script I run:

curl url_GitHub | bash -s url_download_app

The script on GitHub:

#! /bin/sh
url="$2"
filename=$(basename "$url")
workpath=$(dirname $(readlink -f $0))
curl $url -o $workpath/$filename -s
sudo dpkg --install  $workpath/$filename

As I understood it doesn't pass the URL to download the app to the URL="$2" variable.

If I run the GitHub script locally, and pass the URL to download the app, it executes successfully. Smth like:

bash install.sh -s url_download_app

Please help=)

Upvotes: 3

Views: 989

Answers (3)

chepner
chepner

Reputation: 531738

-s appears to be an option intended for the downloaded script. However, it is also an option accepted by bash, so what I think you want is

curl url_GitHub | bash -s -- -s url_download_app

Upvotes: 2

Philippe
Philippe

Reputation: 26697

As the script on GitHub use $2, we should pass it as second argument :

curl url_GitHub | bash -s _ url_download_app

_ url_download_app will be passed to the script on GitHub.

Upvotes: 1

urban
urban

Reputation: 5702

What about the following (using process substitution):

bash <(curl -Ss url_GitHub) url_download_app

I did a proof of concept with the following script:

$ cat /tmp/test.sh 
#!/bin/bash
echo "I got '$1'"
exit 0

and when you run it you get:

$ bash <(cat /tmp/test.sh) "test input argument"
I got 'test input argument'

Upvotes: 0

Related Questions