Loop of form “for i in {1..171}” not working (only loops once, with i='{1..171}')

不羁岁月 提交于 2020-03-01 06:06:56

问题


I am trying to wget files from a range of URLs. Following is my bash script

for i in {1..171}
do
    wget --mirror --random-wait -R gif,jpg,pdf  "http://www.example.com/member/members-directory/?mode=paging&Keyword=&Type=&pg="$i
done

It is just downloading one page.

But I am getting to see on my terminal that

Last-modified header missing -- time-stamps turned off.
2013-11-16 11:56:06 (34.2 KB/s) - `www.example.com/member/members-directory/index.html?mode=paging&Keyword=&Type=&pg={1..171}' saved [31073]

But as output all I got is one page.


回答1:


Let me guess, it's downloading only the page http://www.example.com/member/members-directory/?mode=paging&Keyword=&Type=&pg={1..171} ? That is, not expanding {1..171} correctly.

Keep in mind that the {N..M} style sequence generation only works in bash, typically not in sh. So if the shebang of your script is #!/bin/sh try changing it to #!/bin/bash.



来源:https://stackoverflow.com/questions/20015611/loop-of-form-for-i-in-1-171-not-working-only-loops-once-with-i-1-171

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!