bug-bash
[Top][All Lists]
Advanced

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

Re: Brace expansion bug


From: Chet Ramey
Subject: Re: Brace expansion bug
Date: Tue, 27 Mar 2012 13:19:00 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 3/26/12 6:32 AM, Dan Douglas wrote:
> Hi, hopefully a self-explanatory one today:
> 
>     ~ $ ( set -x -- {a..c}; echo "${*-"{1..3}"}" )
>     + echo 'a b c' 'a b c' 'a b c'
>     a b c a b c a b c
> 
>     ~ $ ( set -x -- {a..c}; echo "${*/"{1..3}"/$*}" )
>     + echo 'a b c' 'a b c' 'a b c'
>     a b c a b c a b c
> 
> I'm told similar glitches have been found before. Looks like this applies to 
> anything that has this sort of replacement context that contains valid brace 
> expansion syntax inside quotes.

Brace expansion doesn't actually know very much shell syntax.  It's a
totally separate part of the word expansion process, and is completely
text-based.

I sometimes wish there were an expanded tracing mode, one that would
display intermediate results after each stage of word expansion.  I've
implemented it before, but only for debugging.

In this case, the first construct expands to

        "${*-"1"}" "${*-"2"}" "${*-"3"}"

which, since the positional parameters are set, expands to three quoted
strings, each containing the expansion of "$*".

Similarly, the second expands to

        "${*/"1"/$*}" "${*/"2"/$*}" "${*/"3"/$*}"

for which the substitution is unsuccessful.

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/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9x9nsACgkQu1hp8GTqdKsqIQCeNo0NPVoPlQYB1JSpivGxZXd7
3EAAnRdZdsnMbW3GIJEcLnhym5u/2/xc
=PQoh
-----END PGP SIGNATURE-----



reply via email to

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