Re: incorrect brace expansion when using default values

2006-09-08 Thread Alexander Elgert
Tatavarty Kalyan schrieb am 08.09.2006 um 11:44:47 (+0800):
 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} ; }

Yes, of course. ;)
It so simple, just eval the braces and nothing else.
I did one step too much and discovered that ab is atomar and underlies no 
further evaluation.
So my assumption is correct for this example only, but not for any possible 
string replacing ab as yours.

Alexander


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


Re: incorrect brace expansion when using default values

2006-09-08 Thread Chet Ramey
Chris F.A. Johnson wrote:

Quote them, and they do expand:
 
 $ foo() { echo ${1:-a{b,c}} ; }
 $ foo
 ab ac

Brace expansion is essentially separate from the rest of the expansions:
in fact, it's designed to be part of a separate library if desired.  As
such, it doesn't implement all of the shell's somewhat quirky quoting
semantics.  It understands simple single- and double-quoted strings and
backslash escapes.  The manual is perhaps not as clear about this as it
could be.

The quoted string, once the brace expansion code finishes, comes out like
this:

${1:-ab} ${1:-ac}

From there, the results observed should be understandable.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/


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


Re: incorrect brace expansion when using default values

2006-09-07 Thread Alexander Elgert
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.

Alexander Elgert


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


Re: incorrect brace expansion when using default values

2006-09-07 Thread Tatavarty Kalyan

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


Re: incorrect brace expansion when using default values

2006-09-06 Thread Andreas Schwab
[EMAIL PROTECTED] (Paul Jarc) writes:

 Mike Frysinger [EMAIL PROTECTED] wrote:
 this little bit of code doesnt work right:
 foo() { echo ${1:-a{b,c}} ; }

 Brace expansion happens before parameter expansion (man bash,
 EXPANSION).

Brace expansion doesn't come into play here, because the braces are
quoted.

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
And now for something completely different.


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


Re: incorrect brace expansion when using default values

2006-09-06 Thread Mike Frysinger
On Wednesday 06 September 2006 05:04, 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}} ; }
 
  Brace expansion happens before parameter expansion (man bash,
  EXPANSION).

 Brace expansion doesn't come into play here, because the braces are
 quoted.

without quotes has the same behavior
foo() { echo ${1:-a{b,c}} ; }
-mike


pgp33m2mxSCoE.pgp
Description: PGP signature
___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: incorrect brace expansion when using default values

2006-09-06 Thread Chris F.A. Johnson
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.


 Brace expansion happens before parameter expansion (man bash,
 EXPANSION).

 Brace expansion doesn't come into play here, because the braces are
 quoted.

   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?

-- 
   Chris F.A. Johnson  http://cfaj.freeshell.org
   ===
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


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


Re: incorrect brace expansion when using default values

2006-09-05 Thread Paul Jarc
Mike Frysinger [EMAIL PROTECTED] wrote:
 this little bit of code doesnt work right:
 foo() { echo ${1:-a{b,c}} ; }

Brace expansion happens before parameter expansion (man bash,
EXPANSION).  So the first } ends the parameter expression, and the
second } isn't special.  The result of parameter expansion is not
subject to brace expansion.

 $ foo
 a{b,c}

This is correct.  a{b,c is the default value, and } follows the
parameter expression.

 $ foo 1
 a}

I get 1}.


paul


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


Re: incorrect brace expansion

2006-01-29 Thread Bob Proulx
Mike Frysinger wrote:
 bash -c 'echo a-{b}-c'
 a-{b}-c
 
 seems to me  current behavior is inconsistent

Yes.  That is inconsistent with csh.

  csh -c 'echo a-{b}-c'
  a-b-c

It is related to brace expansion but seems like a different case than
the original poster's bug report.  In the original poster's case they
wanted the to see the braces output but here your exampld is a case
where they are being output and yet they should not be.

The bash manual documents this as Patterns to be brace expanded take
the form of an optional PREAMBLE, followed by either a series of
comma-separated strings or a sequnce expression between a pair of
braces, followed by an optional POSTSCRIPT.  Your example did not
have either comma-separated strings nor a sequence and therefore does
not qualify for brace expansion and should have been left verbatim.
And yet bash did brace expansion anyway.  That is an inconsistency.

Bob


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


Re: incorrect brace expansion

2006-01-29 Thread Mike Frysinger
On Sunday 29 January 2006 17:25, Bob Proulx wrote:
 The bash manual documents this as Patterns to be brace expanded take
 the form of an optional PREAMBLE, followed by either a series of
 comma-separated strings or a sequnce expression between a pair of
 braces, followed by an optional POSTSCRIPT.  Your example did not
 have either comma-separated strings nor a sequence and therefore does
 not qualify for brace expansion and should have been left verbatim.
 And yet bash did brace expansion anyway.  That is an inconsistency.

a-{b}-c was not brace expanded, ok, good

a-{b{d,e}}-c was expanded too many times ... the output should have been 
a-{bd}-c a-{be}-c ... just cause csh does it differently doesnt really matter 
imo

as you pointed out, the docs say that the brace expansion should only happen 
when commas or sequence expressions are used, and while the inner braces used 
commads, the outer braces did not
-mike


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


Re: incorrect brace expansion

2006-01-29 Thread William Park
On Sun, Jan 29, 2006 at 05:37:56PM -0500, Mike Frysinger wrote:
 On Sunday 29 January 2006 17:25, Bob Proulx wrote:
  The bash manual documents this as Patterns to be brace expanded
  take the form of an optional PREAMBLE, followed by either a series
  of comma-separated strings or a sequnce expression between a pair of
  braces, followed by an optional POSTSCRIPT.  Your example did not
  have either comma-separated strings nor a sequence and therefore
  does not qualify for brace expansion and should have been left
  verbatim.  And yet bash did brace expansion anyway.  That is an
  inconsistency.
 
 a-{b}-c was not brace expanded, ok, good
 
 a-{b{d,e}}-c was expanded too many times ... the output should have
 been a-{bd}-c a-{be}-c ... just cause csh does it differently doesnt
 really matter imo
 
 as you pointed out, the docs say that the brace expansion should only
 happen when commas or sequence expressions are used, and while the
 inner braces used commads, the outer braces did not -mike

Let's see...
a-{b{d,e}}-c
a-{bd,be}-c
a-bd-c a-be-c

It looks okey, I think.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


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


Re: incorrect brace expansion

2006-01-29 Thread Chris F.A. Johnson

On Sun, 29 Jan 2006, William Park wrote:


On Sun, Jan 29, 2006 at 05:37:56PM -0500, Mike Frysinger wrote:

On Sunday 29 January 2006 17:25, Bob Proulx wrote:

The bash manual documents this as Patterns to be brace expanded
take the form of an optional PREAMBLE, followed by either a series
of comma-separated strings or a sequnce expression between a pair of
braces, followed by an optional POSTSCRIPT.  Your example did not
have either comma-separated strings nor a sequence and therefore
does not qualify for brace expansion and should have been left
verbatim.  And yet bash did brace expansion anyway.  That is an
inconsistency.


a-{b}-c was not brace expanded, ok, good

a-{b{d,e}}-c was expanded too many times ... the output should have
been a-{bd}-c a-{be}-c ... just cause csh does it differently doesnt
really matter imo

as you pointed out, the docs say that the brace expansion should only
happen when commas or sequence expressions are used, and while the
inner braces used commads, the outer braces did not -mike


Let's see...
   a-{b{d,e}}-c
   a-{bd,be}-c
   a-bd-c a-be-c

It looks okey, I think.


Except that b{d,e} expands to 'bd be', not 'bd,be'.

--
   Chris F.A. Johnson  http://cfaj.freeshell.org
   ===
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


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


Re: incorrect brace expansion

2006-01-29 Thread Mike Frysinger
On Sunday 29 January 2006 19:23, William Park wrote:
 Let's see...
 a-{b{d,e}}-c
 a-{bd,be}-c

i'm pretty sure the commas are consumed in the expansion

side note, this also fails:
$ echo {a}{b,c}
{a}{b,c}
-mike


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


Re: incorrect brace expansion

2006-01-29 Thread William Park
On Sun, Jan 29, 2006 at 07:33:14PM -0500, Chris F.A. Johnson wrote:
 On Sun, 29 Jan 2006, William Park wrote:
 Let's see...
a-{b{d,e}}-c
a-{bd,be}-c
a-bd-c a-be-c
 
 It looks okey, I think.
 
 Except that b{d,e} expands to 'bd be', not 'bd,be'.

Hmm... no.  Internally, {d,e} gets converted to array of 2 strings, ie.
array[0] = d;
array[1] = e;
Then, prefix and suffix are attached.  So, when prefix 'b' is attached,
you have
array[0] = bd;
array[1] = be;
This continues recursively (left to right, I believe).

When you attach the second prefix 'a-' and suffix '-c', the results are
array[0] = a-bd-c;
array[1] = a-be-c;
Now, you can argue that suffix/prefix are 'a-{' and '}-c', in which
case, you get 
array[0] = a-{bd}-c;
array[1] = a-{be}-c;

I think, it's matter of taste. :-)

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


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


Re: incorrect brace expansion

2006-01-29 Thread Mike Frysinger
On Sunday 29 January 2006 20:08, William Park wrote:
 On Sun, Jan 29, 2006 at 07:33:14PM -0500, Chris F.A. Johnson wrote:
  On Sun, 29 Jan 2006, William Park wrote:
  Let's see...
 a-{b{d,e}}-c
 a-{bd,be}-c
 a-bd-c a-be-c
  
  It looks okey, I think.
 
  Except that b{d,e} expands to 'bd be', not 'bd,be'.

 Hmm... no.  Internally,

arguing for what goes on internally shouldnt have bearing on what the user 
result is ... and in this case, the user result would be as Chris says imho
-mike


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


Re: incorrect brace expansion

2006-01-29 Thread Chet Ramey
William Park wrote:

 side note, this also fails:
 $ echo {a}{b,c}
 {a}{b,c}
 -mike
 
 But,
 echo {b,c}{x}
 prints the correct result,
 b{x} c{x}
 
 Well, gentlemen, we've found a bug.  Anyone sending in a patch?  I don't
 use multiple braces that often, so it doesn't bother me. :-)

Don't bother, I already fixed it.  When I fixed the problems with braces
that don't begin a valid brace expansion sequence, it was easy to change
the behavior you're arguing about.  The old csh-compatible behavior will
be available with a #define.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
Live Strong.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/


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