Binarus wrote:

> The script
> 
> echo 'line1' > file
> echo 'line2' >> file
> RESULT=$(cat file)
> echo "$RESULT"
> 
> gives the following output:
> 
> line1
> line2
> 
> I don't understand why: the command substitution $(cat file) is not
> within double quotes, so word splitting should be applied to the
> result of the substitution and any embedded newlines should be
> removed. Thus, $RESULT should contain text without newlines after line
> three in the above script is executed.

Word splitting does not happen in variable assignment. So

RESULT=$(cat file)

puts literally

line1
line2

in RESULT. When you later do echo "$RESULT", quoting the variable preserves 
its value.

Reply via email to