How does bash parse quotes in this example? -
i running example , trying figure out how arguments parsed.
colour1="red" colour2="light blue" colour3="dark green" x in "$colour1" $colour2" $colour3" echo $x done
note weird missing quotes not typo. it's test example blog.
the output
red
light
blue dark green
the output expected
red
light
blue
dark green
since colour2 won't protected quotes colour1 , colour3 should be. interpreter doing?
because $colour2
, "$ colour3"
adjacent, form single word before parameter expansion occurs. here's how expansion progresses:
- you start
$colour2" $colour3"
- parameter expansion turns
light blue" dark green"
- word-splitting applied result of expansion on unquoted whitespace. there 1 unquoted space, 2 resulting words
light
,blue" dark green"
. - finally quote removal performed, yielding
light
,blue dark green
.
Comments
Post a Comment