On 12/17/09 6:02 AM, Zoltan Mate wrote: > Dear Chet Ramey, > > I have a conversation on an other bug forum, then have been directed > to here, I cannot find any documentation, why
You have to read the section on word splitting. The output of command substitution is subject to word splitting, unless the substitution is quoted. > $ echo $(echo "'alfa beta'") > gives 'alfa beta' whith reduced space, instead of the result of the > following more logical ways: > > $ echo $(echo "'alfa beta'") > the second term suggests one parameter being substituted as > "<the output of the command>" It helps to think about the output of each step in the word expansion process and how that feeds the next step. The command executed in a subshell is echo "'alpha beta'" The output is 'alpha beta'<newline> which is read by the calling shell as the results of the command substitution. The command substitution code removes the trailing newline and passes the 'alpha beta' to the word splitting step. Since that word is not quoted, it is subject to word splitting. The splitting results in two words: "'alpha" and "beta'". Those two words are passed to echo as separate arguments. echo outputs its arguments separated by spaces and ends with a newline. There is a program in the bash distribution named `recho' that makes it clearer. When I run recho $(echo "'alpha beta'") I get the following: argv[1] = <'alpha> argv[2] = <beta'> Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/