Bash script execute wget with a variable inside it

21,629

Solution 1

Four things:

  1. Add quotes around your URL: http:://www.myurl.com ==> "http:://www.myurl.com"
  2. Remove the double colon: "http:://www.myurl.com" ==> "http://www.myurl.com"
  3. Get rid of the extra flags and hyphen on the wget command: "wget -O - -q "$URL/something/something2"" ==> wget "$URL/something/something2"
  4. 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!)

Share:
21,629
Broshi
Author by

Broshi

Updated on February 06, 2021

Comments

  • Broshi
    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"