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:

  1. you start $colour2" $colour3"
  2. parameter expansion turns light blue" dark green"
  3. word-splitting applied result of expansion on unquoted whitespace. there 1 unquoted space, 2 resulting words light , blue" dark green".
  4. finally quote removal performed, yielding light , blue dark green.

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -