循环使用 wget 下载一系列数字

Szy*_*oda 15 bash wget shell-script

如何编写将执行以下操作的 bash 脚本:

URL = "example.com/imageID="
while (1..100)
   wget URL + $i #it will wget example.com/imageID=1, then 2, then 3, etc
done
Run Code Online (Sandbox Code Playgroud)

所以我有许多循环要执行,一个以循环中的数字结尾的 URL。我需要wget所有这些。

小智 30

如果您使用的是 Bash 4.0,您可以这样做:

wget example.com/imageId={1..100}.jpg
Run Code Online (Sandbox Code Playgroud)


Can*_*nha 12

即使对于没有太多编程经验的人来说,这也相当容易。如有疑问,请务必阅读Bash手册:

for i in {1..100}
do
    wget "example.com/imageID=$i"
done
Run Code Online (Sandbox Code Playgroud)