0

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?

1 Answer 1

1
#!/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
Sign up to request clarification or add additional context in comments.

3 Comments

I actually want it to be interactive, as opposed to taking an argument -- the main question was "can I use a $variable in a call to cURL". Thanks for your help!
@Micha, I added the interactive script for the same purpose. See my EDIT.
The lack of quotes is a robustness problem. See When to wrap quotes around a shell variable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.