0

I need to write a loop where I need to pass a "token" (which is fixed) and a variable (i) in the url. Is there any way I can achieve that? I wrote the following code but it is not working. If I put double quotes around the entire url it doesn't work

for ((i=1;i<=100;i++)); do 
    curl -O "https://api.mysite.com/info?&access_token=xyx"&page=i
done
  • Please explain a bit better what you are trying to obtain. Maybe with examples. Posting the errors also helps. One sure mistake in your command is that you have to use $i after page=. – Luis Antolín Cano Nov 11 '14 at 21:28

1 Answers1

0

The character & is special syntax in the shell, so what you've written runs the curl command in the background and runs the command page=i in the foreground. You need to put it inside the quotes.

To refer to the value of a variable, put a $ before it. A variable substitution looks like this: $i — and it must be inside double quotes, not inside single quotes. You can also leave variable substitutions unquoted, but that further expands the value of the variable so don't do it until you understand when it's safe — only use $i inside double quotes.

for ((i=1; i<=100; i++)); do 
    curl -O "https://api.mysite.com/info?access_token=xyx&page=$i"
done