Reputation: 33
I am running an example and trying to figure out how the arguments were parsed.
colour1="red"
colour2="light blue"
colour3="dark green"
for X in "$colour1" $colour2" $colour3"
do
echo $X
done
Note that the weird missing quotes are not a typo. It's just a test example from a blog.
The output I get is
red
light
blue dark green
The output I expected was
red
light
blue
dark green
since colour2 won't be protected by quotes but colour1 and colour3 should be. What is the interpreter doing?
Upvotes: 3
Views: 35
Reputation: 531245
Because $colour2
and "$ colour3"
are immediately adjacent, they form a single word before parameter expansion occurs. Here's how the expansion progresses:
$colour2" $colour3"
light blue" dark green"
light
and blue" dark green"
.light
and blue dark green
.Upvotes: 4