$ cat fav
#!/bin/bash
for i in {1..7}
do
echo http://api.stackoverflow.com/1.0/users/113124/favorites?page=$i&pagesize=100
done
$ ./fav
http://api.stackoverflow.com/1.0/users/113124/favorites?page=1
http://api.stackoverflow.com/1.0/users/113124/favorites?page=3
http://api.stackoverflow.com/1.0/users/113124/favorites?page=6
http://api.stackoverflow.com/1.0/users/113124/favorites?page=5
http://api.stackoverflow.com/1.0/users/113124/favorites?page=7
http://api.stackoverflow.com/1.0/users/113124/favorites?page=4
http://api.stackoverflow.com/1.0/users/113124/favorites?page=2
$
- Why don’t I get
&pagesize=100at the end? - Also, why are the results out of order?
&runs a program in the background, and it’s also an “end of command” indicator just like;, which is why your command is cut short. You can escape it with\or put the whole thing in double quotes:Interestingly,
pagesize=100was also being executed as a separate command, but that is actually a valid variable assignment. So it wasn’t generating an error message which might have clued you in to what was happening.The backgrounding means all of the echo statements were executed in parallel. That explains why they ended up being executed in random order since the seven processes will finish in an indeterministic order based on when they get time slices from the kernel.