user7055548
user7055548

Reputation: 11

Making wget a bash.sh

Need help turning this wget string in to a bash script because I use it frequently. wget -nd -H -r -l 1 -A jpg,jpeg,bmp,gif,png,mp4,webm -e robots=off

So far I have tried

#!/bin/bash
wget -nd -H -r -l 1 -A jpg,jpeg,bmp,gif,png,mp4,webm -e robots=off "${URL}"

When I do

myscript.sh http://example.com/where/thefilesare

I get

http://: Invalid host name.

Upvotes: 0

Views: 928

Answers (1)

Hugh Rawlinson
Hugh Rawlinson

Reputation: 989

The following should work

#!/bin/bash
wget -nd -H -r -l 1 -A jpg,jpeg,bmp,gif,png,mp4,webm -e robots=off $1

The reason that your script doesn't work is because the script doesn't know where to get URL from. $1 simply refers to the first argument of the script. If this script gets much more complicated, I'd recommend reading up on how to parse command line arguments in bash. This StackOverflow answer seems like a good place to start.

Also, you could put this command as an alias in your shell rc file, or your shell profile file, which has various advantages including being able to move it round easily as part of a dotfiles git repository.

Upvotes: 1

Related Questions