hamster
hamster

Reputation: 21

Bash script to download JPG files from the website

I am a completely beginner in programming bash scripts (Linux, Debian), one of the use that I'd like to write is to make user able to download JPG or any other kind of graphic files from website he needs to, eg ./code1.sh www.bbc.com. It doesn't interpret a website adress, an error shows: there is no such a file or catalog like www.bbc.com. Could you please write me what am I doing wrong?

#!/bin/bash
$1
curl $1 | grep -o -e `$1.\{1,100\}\.jpg` > graph_list.txt
wget `cat graph_list.txt`

Upvotes: 0

Views: 1848

Answers (1)

Michael Jaros
Michael Jaros

Reputation: 4681

Try this line with a simplified regular expression. This will get all the pictures (I'm not sure if I fully understand how you wanted to filter):

curl www.bbc.com | grep -o -e 'http[^"]*\.jpg' | xargs wget

Your code posted in the question cannot work because of the backticks (`) you used to wrap your regular expression. Backticks trigger command substitution in Bash like you intentionally did in your last line, use quotes (') to prevent tokenization and expansion or double quotes (") to prevent tokenization instead.

Upvotes: 1

Related Questions