Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script execute wget with a variable inside it

Tags:

linux

bash

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"
like image 516
Broshi Avatar asked May 07 '15 16:05

Broshi


2 Answers

I use that code in IPython (colab):


URL = 'http:://www.myurl.com'
!wget {URL}

I wrote this answer because was searching it!)

like image 40
Kobap Bopy Avatar answered Nov 09 '22 16:11

Kobap Bopy


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}"
like image 176
Dave McMordie Avatar answered Nov 09 '22 16:11

Dave McMordie