Reputation: 770
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;
Upvotes: 9
Views: 12805
Reputation: 2836
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
Upvotes: 1
Reputation: 50034
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
Upvotes: 19