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
3
  • 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
    Jan 7, 2013 at 7:35
  • @Micha, I added the interactive script for the same purpose. See my EDIT.
    – Suku
    Jan 7, 2013 at 8:28
  • The lack of quotes is a robustness problem. See When to wrap quotes around a shell variable?
    – tripleee
    Dec 24, 2022 at 21:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.