On 2/18/11 4:32 PM, Peter Hofmann wrote: > So far, so good. It's what I expected. Let's add another level of > quotes: > > $ echo "$(echo "{1..3}")" > 1 2 3 > > Huh? Actually, I was expecting to get the same output as before. > > Some debug output: > > $ set -x > $ echo "$(echo "{1..3}")" > ++ echo 1 > ++ echo 2 > ++ echo 3 > + echo 1 2 3 > 1 2 3 > > Why's that? > > a) As far as I understood, quotes inside of $(...) should not interfere > with the outer quotes. > b) Why are there three subshells? Actually, that {1..3} doesn't get > expanded. It's more like the call above is effectively equivalent to > this: > > $ echo "$(echo 1)" "$(echo 2)" "$(echo 3)"
This is close to the actual expansion. Brace expansion is strictly textual, is performed before all other expansions, and doesn't understand a whole lot of shell syntax. It does understand a little about quoted strings, so what you get is echo "$(echo "1")" "$(echo "2")" "$(echo "3")" The preamble is "$(echo ", the portion to be expanded is {1..3}, and the postscript is ")". 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/