I used to think that bash expanded something like "$<var>"
simply by replacing "textually" $<var>
with the content of <var>
. However after coming across some examples, I realized that I'm missing something. Consider the following interaction.
1: $ X="A; B"
2: $ printf "%s\n" $X
3: A;
4: B
5: $ printf "%s\n" "A; B"
6: A; B
7: $ printf "%s\n" A; B
8: A
9: B: command not found
As you can see, the output of line 2 is different from that of line 5, so in this case $X
expansion is not a simple textual substitution. Even removing the double quotes (line 7) doesn't work.
Can someone explain how exactly these situations are handled by bash?