Re: excess braces ignored: bug or feature ?

2012-03-28 Thread Davide Baldini
On 02/17/12 20:51, Mike Frysinger wrote:
> FOO= BAR=bar
> : ${FOO:=${BAR}
> echo $FOO

Why should this be a bug? Your second line performs a parameter
expansion, all the remaining characters are joint into the token and
passed to ':'.
No bug.


Re: excess braces ignored: bug or feature ?

2012-02-21 Thread Chet Ramey
On 2/20/12 4:17 AM, Dan Douglas wrote:
> On Sunday, February 19, 2012 04:25:46 PM Chet Ramey wrote:
> 
>> I assume you mean the first one.  It doesn't matter whether or not the
>> variable is set as a side effect of the redirection -- it's in a
>> subshell and disappears.
>>
>> Chet
> 
> Forgot to mention though, It's possible in ksh there is no subshell created 
> if 
> you consider this:

The best way to tell for sure is with a system call tracer.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: excess braces ignored: bug or feature ?

2012-02-21 Thread Chet Ramey
On 2/20/12 2:32 AM, Dan Douglas wrote:

>>> That one really is ignored. No variable named xxx... is actually set.
>>
>> I assume you mean the first one.  It doesn't matter whether or not the
>> variable is set as a side effect of the redirection -- it's in a
>> subshell and disappears.
>>
>> Chet
> 
> Oh so a subshell is created after all, and that really is a command 
> substitution + redirect! I just chalked it up to Bash recycling the way 
> redirects were parsed.

Bash always forks for command substitution.  It defers parsing the command
between the parens until it's needed, and so doesn't notice that it's only
a redirection until it has already forked.  It is able to skip the exec and
dump the file out directly.

> 
> I think I ran across that quirk in trying to determine whether $( special command substitution or it's own kind of expansion but couldn't think 
> of a way to test it. 

It's a special command substitution (there are others).  David has gone to
great lengths to  avoid forking in ksh93 wherever possible; I assume this
is one of those  places where he's managed to do so.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: excess braces ignored: bug or feature ?

2012-02-20 Thread Dan Douglas
On Sunday, February 19, 2012 04:25:46 PM Chet Ramey wrote:

> I assume you mean the first one.  It doesn't matter whether or not the
> variable is set as a side effect of the redirection -- it's in a
> subshell and disappears.
> 
> Chet

Forgot to mention though, It's possible in ksh there is no subshell created if 
you consider this:

$ : "$(&2;})"
1
$ : $(: $( echo ${.sh.subshell} >&2))
2

It even works with the subshell-less command substitution, but there's no 
typeset output, so either x is automatically unset, it's never set to begin 
with, or ${ &2 | :
0
 ~ $ : | { echo $BASH_SUBSHELL >&2; } | :   



1
 ~ $ : | ( echo $BASH_SUBSHELL >&2; ) | :   



1
 ~ $ : | ( ( echo $BASH_SUBSHELL >&2; ) ) | :   



2
 ~ $ : | { ( echo $BASH_SUBSHELL >&2; ) } | :   


   
2
 ~ $ : | { { echo $BASH_SUBSHELL >&2; } } | :   


   
1

-- 
Dan Douglas



Re: excess braces ignored: bug or feature ?

2012-02-19 Thread Dan Douglas
On Sunday, February 19, 2012 04:25:46 PM Chet Ramey wrote:
> On 2/17/12 6:22 PM, Dan Douglas wrote:
> > My favorite is probably the parser ignoring any valid redirection syntax
> > with the special command substitutions.
> > 
> >  ~ $ { echo "$({} > 
> > hi
> 
> Bash does the same thing as ksh93 here, though for the wrong reasons.
> I think ksh93 counts an input redirection that saves the file descriptor
> into a variable as sufficient to kick in the `equivalent to cat file'
> clause.
> 
> >  ~ $ { echo "$(11 > 
> > hi
> 
> This is a bug.  It should be a file descriptor out of range error, or
> it should treat the string of digits as a word, since the value
> exceeds the largest intmax_t.
> 
> > That one really is ignored. No variable named xxx... is actually set.
> 
> I assume you mean the first one.  It doesn't matter whether or not the
> variable is set as a side effect of the redirection -- it's in a
> subshell and disappears.
> 
> Chet

Oh so a subshell is created after all, and that really is a command 
substitution + redirect! I just chalked it up to Bash recycling the way 
redirects were parsed.

I think I ran across that quirk in trying to determine whether $(&2;})"

...only to discover that ${ cmd;} also increments .sh.subshell anyway (like 
BASH_SUBSHELL), and there was no BASHPID equivalent so that was a dead end.
-- 
Dan Douglas



Re: excess braces ignored: bug or feature ?

2012-02-19 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2/17/12 6:22 PM, Dan Douglas wrote:

> My favorite is probably the parser ignoring any valid redirection syntax with 
> the special command substitutions.
> 
>  ~ $ { echo "$({} hi

Bash does the same thing as ksh93 here, though for the wrong reasons.
I think ksh93 counts an input redirection that saves the file descriptor
into a variable as sufficient to kick in the `equivalent to cat file'
clause.

>  ~ $ { echo "$(11 hi

This is a bug.  It should be a file descriptor out of range error, or
it should treat the string of digits as a word, since the value
exceeds the largest intmax_t.

> That one really is ignored. No variable named xxx... is actually set.

I assume you mean the first one.  It doesn't matter whether or not the
variable is set as a side effect of the redirection -- it's in a
subshell and disappears.

Chet
- -- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9BaM4ACgkQu1hp8GTqdKvbMACfYfcdTfKqCrQrygNGq4SU0RCP
LFEAn3p2zlTl0bZueNB5fy8FLNTDa45L
=6ptf
-END PGP SIGNATURE-



Re: excess braces ignored: bug or feature ?

2012-02-19 Thread Chet Ramey
On 2/17/12 2:51 PM, Mike Frysinger wrote:
> can't tell if this is a bug or a feature.
> 
> FOO= BAR=bar
> : ${FOO:=${BAR}
> echo $FOO
> 
> i'd expect an error, or FOO to contain those excess braces.  instead, FOO is 
> just "bar".

Neither.  That's just how parameter expansion works.  The braces are
contained in the remainder of the word expansion.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: excess braces ignored: bug or feature ?

2012-02-17 Thread Dan Douglas
On Friday, February 17, 2012 02:51:27 PM Mike Frysinger wrote:
> can't tell if this is a bug or a feature.
> 
> FOO= BAR=bar
> 
> : ${FOO:=${BAR}
> 
> echo $FOO
> 
> i'd expect an error, or FOO to contain those excess braces.  instead, FOO is
> just "bar".
> -mike

My favorite is probably the parser ignoring any valid redirection syntax with 
the special command substitutions.

 ~ $ { echo "$({}

signature.asc
Description: This is a digitally signed message part.


Re: excess braces ignored: bug or feature ?

2012-02-17 Thread Bob Proulx
Greg Wooledge wrote:
> Mike Frysinger wrote:
> > can't tell if this is a bug or a feature.
> > 
> > FOO= BAR=bar
> > : ${FOO:=${BAR}
> > echo $FOO
> > 
> > i'd expect an error, or FOO to contain those excess braces.  instead, FOO 
> > is 
> > just "bar".
> 
> imadev:~$ : ${FOO:=BAR}
> imadev:~$ echo "$FOO"
> BAR
> 
> It looks OK to me.  You've got an argument word which happens to contain
> a substitution-with-side-effects as part of it.

Or slightly differently expressed it is this too:

  $ echo ${FOO:=BAR}
  BAR

  $ echo ${FOO:=BAR}
  BAR

  $ echo ${FOO:=${BAR}
  }}}

Seems reasonable to me.  In that context the bracket isn't special in
any way and is just another character in the string.  Just like this:

  $ echo 
  

Bob



Re: excess braces ignored: bug or feature ?

2012-02-17 Thread Greg Wooledge
On Fri, Feb 17, 2012 at 02:51:27PM -0500, Mike Frysinger wrote:
> can't tell if this is a bug or a feature.
> 
> FOO= BAR=bar
> : ${FOO:=${BAR}
> echo $FOO
> 
> i'd expect an error, or FOO to contain those excess braces.  instead, FOO is 
> just "bar".

imadev:~$ : ${FOO:=BAR}
imadev:~$ echo "$FOO"
BAR

It looks OK to me.  You've got an argument word which happens to contain
a substitution-with-side-effects as part of it.



excess braces ignored: bug or feature ?

2012-02-17 Thread Mike Frysinger
can't tell if this is a bug or a feature.

FOO= BAR=bar
: ${FOO:=${BAR}
echo $FOO

i'd expect an error, or FOO to contain those excess braces.  instead, FOO is 
just "bar".
-mike


signature.asc
Description: This is a digitally signed message part.