How to use mod operator in bash?

流过昼夜 提交于 2019-12-02 14:19:51
Mark Longair

Try the following:

 for i in {1..600}; do echo wget http://example.com/search/link$(($i % 5)); done

The $(( )) syntax does an arithmetic evaluation of the contents.

Chris Eberle
for i in {1..600}
do
    n=$(($i%5))
    wget http://example.com/search/link$n
done

You must put your mathematical expressions inside $(( )).

One-liner:

for i in {1..600}; do wget http://example.com/search/link$(($i % 5)); done;

Multiple lines:

for i in {1..600}; do
    wget http://example.com/search/link$(($i % 5))
done
h__

This might be off-topic. But for the wget in for loop, you can certainly do

curl -O http://example.com/search/link[1-600]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!