[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Command substitution / word splitting question
From: |
Chet Ramey |
Subject: |
Re: Command substitution / word splitting question |
Date: |
Wed, 05 May 2010 09:39:47 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 |
On 4/23/10 4:17 AM, 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.
The rhs of assignment statements is not subject to word splitting.
Assignment statements are treated differently than arguments to simple
commands.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/