Bash script execute wget with a variable inside it
21,629
Solution 1
Four things:
- Add quotes around your URL: http:://www.myurl.com ==> "http:://www.myurl.com"
- Remove the double colon: "http:://www.myurl.com" ==> "http://www.myurl.com"
- Get rid of the extra flags and hyphen on the wget command: "wget -O - -q "$URL/something/something2"" ==> wget "$URL/something/something2"
- Add curly braces around your variable: "wget "$URL/something/something2"" ==> "wget "${URL}/something/something2""
This works:
#!/bin/bash
URL="http://www.google.com"
echo $(date) 'Running wget...'
wget "${URL}"
Solution 2
I use that code in IPython (colab):
URL = 'http:://www.myurl.com'
!wget {URL}
I wrote this answer because was searching it!)

Author by
Broshi
Updated on February 06, 2021Comments
-
Broshi almost 2 years
I'm trying to execute a wget command with a variable inside it but it just ignores it, any idea what am I doing wrong?
#!/bin/bash URL=http:://www.myurl.com echo $(date) 'Running wget...' wget -O - -q "$URL/something/something2"