bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Brace expansion inside of command substitution - broken or is it me?


From: Chet Ramey
Subject: Re: Brace expansion inside of command substitution - broken or is it me?
Date: Fri, 18 Feb 2011 19:26:18 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7

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    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]