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: Tatavarty Kalyan
Subject: Re: incorrect brace expansion when using default values
Date: Fri, 8 Sep 2006 11:44:47 +0800

On 9/8/06, Alexander Elgert <address@hidden> wrote:

Tatavarty Kalyan schrieb am 07.09.2006 um 14:20:43 (+0800):
> On 9/6/06, Chris F.A. Johnson <address@hidden> wrote:
> >
> >On 2006-09-06, Andreas Schwab wrote:
> >> address@hidden (Paul Jarc) writes:
> >>
> >>> Mike Frysinger <address@hidden> 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.

Yes, as you said the brace expansion is outside the double quotes so
shouldn't it  be more like:
$ foo() { echo "${1:-"ab"}" "${1:-"ac"}" ; }
For example,
$ foo() { echo "${1:-"a{\'b,c}"}" ; }
$foo
a'b ac
$foo() { echo "${1:-"a\'b"}" "${1:-"ac"}" ; }
$foo
a'b ac



Alexander Elgert


_______________________________________________
Bug-bash mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/bug-bash



reply via email to

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