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?

Micha
  • 147
  • 2
  • 8

1 Answers1

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
Suku
  • 3,820
  • 1
  • 21
  • 23
  • 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 07 '13 at 07:35
  • @Micha, I added the interactive script for the same purpose. See my EDIT. – Suku Jan 07 '13 at 08:28
  • The lack of quotes is a robustness problem. See [When to wrap quotes around a shell variable?](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – tripleee Dec 24 '22 at 21:10