I'm trying a line like this:
for i in {1..600}; do wget http://example.com/search/link $i % 5; done;
What I'm trying to get as output is:
wget http://example.com/search/link0
wget http://example.com/search/link1
wget http://example.com/search/link2
wget http://example.com/search/link3
wget http://example.com/search/link4
wget http://example.com/search/link0
But what I'm actually getting is just:
wget http://example.com/search/link
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]
来源:https://stackoverflow.com/questions/5688576/how-to-use-mod-operator-in-bash