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
To use modulo in the shell, we have to utilize the “expr” command to evaluate its value. So, we have consecutively added three “expr” commands to find out the modulo of two integer values each time by using the “%” operator between them and got three remainder values.
The modulo operation (abbreviated “mod”, or “%” in many programming languages) is the remainder when dividing. For example, “5 mod 3 = 2” which means 2 is the remainder when you divide 5 by 3.
In most programming languages, modulo is indicated with a percent sign. For example, "4 mod 2" or "4%2" returns 0, because 2 divides into 4 perfectly, without a remainder. "5%2", however, returns 1 because 1 is the remainder of 5 divided by 2 (2 divides into 5 2 times, with 1 left over).
Dollar sign $ (Variable) The dollar sign before the thing in parenthesis usually refers to a variable. This means that this command is either passing an argument to that variable from a bash script or is getting the value of that variable for something.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With