9

I need some help with the following simple bash script, where the variable i does not seem to get substituted when running curl (causing an error).

(This is just a simple abstraction of the actual script)

for i in {1..3}
do
  HTML=$(curl -s 'http://example.com/index.php?id=$i')
done;
1
  • 1
    try enclosing in double quotes instead of single quotes Commented Aug 9, 2013 at 6:48

2 Answers 2

19

Variables are not substituted within single quotes. You have to use double quotes in this case:

for i in {1..3}; do
    HTML=$( curl -s "http://example.com/index.php?id=$i" )
done
Sign up to request clarification or add additional context in comments.

Comments

2

From http://tldp.org/LDP/abs/html/varsubn.html

Enclosing a referenced value in double quotes (" ... ") does not interfere with variable substitution. This is called partial quoting, sometimes referred to as "weak quoting." Using single quotes (' ... ') causes the variable name to be used literally, and no substitution will take place. This is full quoting, sometimes referred to as 'strong quoting.'

A

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.