Shell script downloads resources in batches and retains the path. shell downloads resources.
Sample resource list
For example, url.txt:
http://su.bdimg.com/static/superplus/img/logo_white_ee663702.pnghttp://su.bdimg.com/static/superplus/img/logo_white_ee663703.pnghttp://su.bdimg.com/static/superplus/img/logo_white_ee663701.pnghttp://su.bdimg.com/static/superplus/img/logo_white_ee663704.pnghttp://su.bdimg.com/static/superplus/img/logo_white_ee663705.pnghttp://su.bdimg.com/static/superplus/img/logo_white_ee663706.png
We need to download these images and save them in their respective folders.
The script is as follows:
For example, download. sh.
#! /Bin/bash # desc: download resource # author: ten years later, Lu's brother mydir = 'pwd' while read linedo {if [-n "$ line"] then cd $ mydir url = $ (echo "$ line" | tr-d '\ R ') picdir = $ (echo $ url | sed-r's/http: \ // G') picname = $ (echo $ {picdir ##*/}) picpath = $ (echo $ {picdir %/*}) mkdir-p $ picpath cd $ picpath wget-O $ picname 'echo $ url' fi} done <$1 exit 0
Note the following points:
1. Delete the line break at the end of the text file:
tr -d '\r'
2. Obtain the Resource Name:
${picdir##*/}
3. Obtain the resource path:
${picdir%/*}
Run
sh download.sh url.txt