简体   繁体   中英

Wget: read URL from file, add sequence of number to the URL

I am reading a file (with URL's) line by line:

#!/bin/bash
while read line
do
    url=$line
    wget $url
    wget $url_{001..005}.jpg
done < $1

For first, I want to download primary url as you see wget $url . After that I want to add to the url sequence of numbers (_001.jpg, _002.jpg, _003.jpg, _004.jpg, _005.jpg):

wget $url_{001..005}.jpg

...but for some reason it's not working.

Sorry, missed out one thing: the url's are like http://xy.com/052914.jpg . Is there any easy way to add _001 before the extension? http://xy.com/052914_001.jpg . Or I have to remove ".jpg" from the file containing URL's then simply add later to the variable?

转义下划线字符的另一种方法:

wget $url\_{001..005}.jpg

Try encapsulating your variable name:

wget ${url}_{001..005}.jpg

Bash is trying to expand the variable $url_ in your command.

As for your jpg within the URL followup, see substring expansion in the bash manual .

wget ${url:0: -4}_{001..005}.jpg

The :0: -4 means, expand to the variable from position zero (the first character), minus the last 4 characters.

Or from this answer :

wget ${url%.jpg}_{001..005}.jpg

%.jpg removes .jpg specifically and will work on older versions of bash .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM