bug-bash
[Top][All Lists]
Advanced

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

Re: incorrect brace expansion when using default values


From: Alexander Elgert
Subject: Re: incorrect brace expansion when using default values
Date: Thu, 7 Sep 2006 22:42:28 +0200
User-agent: Mutt/1.4.1i

Tatavarty Kalyan schrieb am 07.09.2006 um 14:20:43 (+0800):
> On 9/6/06, Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> >
> >On 2006-09-06, Andreas Schwab wrote:
> >> prj@po.cwru.edu (Paul Jarc) writes:
> >>
> >>> Mike Frysinger <vapier@gentoo.org> wrote:
> >>>> this little bit of code doesnt work right:
> >>>> foo() { echo "${1:-a{b,c}}" ; }
> >
> >  The first '}' is interpreted as the end of the parameter expansion.

It depends on the number of parameters, if the first or second brace is
taken. So this is very likely a Bug. ;)

That means in the case
        foo a
the first brace is taken.
And in the case
        foo
the second one does the termination.

> >  Quote them, and they do expand:
> >
> >$ foo() { echo "${1:-"a{b,c}"}" ; }
> >$ foo
> >ab ac
> >
> >  However, there is a problem:
> >
> >$ foo 1
> >1 1
> >
> >  Where is the second '1' coming from?
> 
> It seems
> 
> foo() { echo "${1:-"a{b,c}"}" ; } expands to
> 
> foo() { echo ${1:-ab} ${1:-ac} ; }

Not exactly, it is acting like:

foo() { echo "${1:-ab}" "${1:-ac}" ; }

To check the first assumption, that there are two parameters to echo, use the
call without any parameters to foo:

        $ foo
        ab ac
        $ 

The show the second, apply a string with spaces:

        $ foo() { echo "${1:-"a{b,c}"}" ; }
        $ foo "            x            "
                    x                         x            
        $ 



It is because the string
        a{b,c}
is outside of the quotes. So the brace expansion comes first and duplicates
the arguments to the echo call.

Alexander Elgert




reply via email to

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