在网上下载时,可以发现有些有规律的连接,如以递增数字命名
http://xx...xx/chapter01.pdf
http://xx...xx/chapter02.pdf
....
http://xx...xx/chapter99.pdf
上面的连接模板为
http://xx...xx/chapter{}.pdf
把{}依次替换为01到99下载即可
下面这个脚本完成这个功能
#!/bin/bash
usage()
{
echo "usage:" >&2
echo "`basename $0` [-p positionwidth] urltemplate min max" >&2
exit 0
}
replace()
{
ins=$2
while [ $3 -gt ${#ins} ]; do
ins="0$ins"
done
echo $1 | sed -e "s/{}/$ins/"
}
poswid=0
while getopts ":p:" opt;
do
case $opt in
p)
poswid=$OPTARG
;;
?)
echo "invalid option -$OPTARG" >&2
usage
;;
esac
done
shift $((OPTIND-1));
if [ $# -ne 3 ]; then
usage
fi
urltpl="http://${1#http://}"
min=$2
max=$3
for i in `seq $min $max`
do
url=`replace $urltpl $i $poswid`
wget $url
done