View Single Post
  #2   (View Single Post)  
Old 27th December 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

What were you expecting? Looks perfectly normal to me J65nko but I'm a bit drowsy....

Code:
Terry@vectra$ echo `cat this-that`
#!/bin/sh THIS=' aa bb cc dd ee ff' THAT=" zz yy xx ww " echo \"THIS: [\${THIS}]\" echo ------------------- echo "THIS: [${THIS}]" echo echo THIS: [\${THIS}] echo ------------------- echo THIS: [${THIS}] echo echo \"THAT: [\${THAT}]\" echo ------------------- echo "THAT: [${THAT}]" echo echo THAT: [\${THAT}] echo ------------------- echo THAT: [${THAT}]

Quote:
Originally Posted by 2.6.3 Command Substitution
The shell shall expand the command substitution by executing command in a subshell environment (see Shell Execution Environment) and replacing the command substitution (the text of command plus the enclosing "$()" or backquotes) with the standard output of the command, removing sequences of one or more <newline>s at the end of the substitution. Embedded <newline>s before the end of the output shall not be removed; however, they may be treated as field delimiters and eliminated during field splitting, depending on the value of IFS and quoting that is in effect.

Quote:
Originally Posted by 2.2.3 Double Quotes
Enclosing characters in double-quotes ( "" ) shall preserve the literal value of all characters within the double-quotes, with the exception of the characters dollar sign, backquote, and backslash, as follows:
There might be more HERE, but I'm to sleepy to parse it right now.



echo "$THIS" preserves things just as you would expect, that's the double quotes job.

echo $THIS substitutes $THIS with the contents of the THIS variable, which I assume is subject to field splitting.

Unless you screw with IFS, echo $THIS should be equivalent to this:

Code:
echo    aa \
bb \
    cc \
dd \
ee \
ff'
Which contains the `words` aa, bb, cc, dd, ee, and ff, plus a new line; because of how the shell does input field splitting!



Maybe I'm just to sleepy or perhaps I missed some trick about the question?
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote