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


11

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

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

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

Answers:


19

如果您使用的是Bash 4.0,则可以执行以下操作:

wget example.com/imageId={1..100}.jpg

10

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

for i in {1..100}
do
    wget "example.com/imageID=$i"
done

原则上,您应该$i在引号中加上以下内容:wget "example.com/imageID=$i"
Scott

这可能很棒。但是,我从“ 00008000”开始,wget拍摄错误,因为在某种程度上它跳过了前四个零。
esaruoho

-1

如果变量不在URL的末尾且变量在下划线之间:
example.com/imageID_1_2018.gif
example.com/imageID_2_2018.gif
example.com/imageID_3_2018.gif



example.com/imageID_100_2018.gif

wget example.com/imageID_{1..100}_2018.gif
等效地:
for ((i=1;i<=100;i++)); do wget example.com/imageID_${i}_2018.gif; done


3
欢迎来到超级用户。请编辑您的答案以提供更多详细信息。并非每个阅读您帖子的人都可以理解它在没有更详细说明的情况下如何回答OP的问题。
我说恢复莫妮卡

1
我不确定这是否是答案。它看起来像是对已接受答案的一种解释(不是一个很明确的答案)。
斯科特(Scott)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.