Re: incorrect brace expansion when using default values
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
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
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
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
[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
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
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
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