Micha
Micha

Reputation: 147

Inserting variables into URLs with bash scripting

Say I want to write a bash script that takes user input, inserts it into a URL and then downloads it. Something like this: #!/bin/bash

cd /path/to/folder

echo Which version?

read version

curl -O http://assets.company.tld/$version/foo.bar

Would this work? If not, how can I do what I'm trying to do?

Upvotes: 0

Views: 5054

Answers (1)

Suku
Suku

Reputation: 3880

#!/bin/bash
version=$1
cd /path/to/folder
echo $version
curl -o $version-foo.bar http://assets.company.tld/$version/foo.bar

where $1 is the first positional argument

So, suppose you save the script with name assets.sh. Then you can using the same like following:

./assests.sh ver1

where ver1 is the version

[EDIT] If you want an interactive session:

#!/bin/bash
version=$1
cd /path/to/folder
echo -n "Which version you want? "
read version
curl -o $version-foo.bar http://assets.company.tld/$version/foo.bar

Upvotes: 1

Related Questions