On 9/8/06, Alexander Elgert <[EMAIL PROTECTED]> wrote:

Tatavarty Kalyan schrieb am 07.09.2006 um 14:20:43 (+0800):
> On 9/6/06, Chris F.A. Johnson <[EMAIL PROTECTED]> wrote:
> >
> >On 2006-09-06, Andreas Schwab wrote:
> >> [EMAIL PROTECTED] (Paul Jarc) writes:
> >>
> >>> Mike Frysinger <[EMAIL PROTECTED]> 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
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

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

Reply via email to