Reputation: 3592
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"
Upvotes: 5
Views: 27886
Reputation: 337
for Kaggle notebook:
url = "https://google.com"
name = "file.f"
!wget "$url" -O "$name"
Upvotes: 0
Reputation: 91
I use that code in IPython (colab):
URL = 'http:://www.myurl.com'
!wget {URL}
I wrote this answer because was searching it!)
Upvotes: 1
Reputation: 84531
Another handy option in Bash (or other shells) is to create a simple helper function that calls wget
with the common options required by nearly all sites and any specific options you generally use. This reduces the typing involved and can also be useful in your scripts. I place the following in my ~/.bashrc to make it available to all shells/subshells. It validates input, checks that wget
is available, and then passes all command line arguments to wget
with the default options set in the script:
wgnc () {
if [ -z $1 ]; then
printf " usage: wg <filename>\t\t(runs wget --no-check-certificate --progress=bar)\n"
elif ! type wget &>/dev/null; then
printf " error: 'wget' not found on system\n"
else
printf " wget --no-check-certificate --progress=bar %s\n" "$@"
wget --no-check-certificate --progress=bar "$@"
fi
}
You can cut down typing even more by aliasing the function further. I use:
alias wg='wgnc'
Which reduces the normal wget --no-check-certificate --progress=bar URL
to simply wg URL
. Obviously, you can set the options to suit your needs, but this is a further way to utilize wget
in your scripts.
Upvotes: 0
Reputation: 573
Four things:
This works:
#!/bin/bash
URL="http://www.google.com"
echo $(date) 'Running wget...'
wget "${URL}"
Upvotes: 8