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 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 $(file) was a 
 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-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-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-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 $({}/dev/stdin); } 'hi'
 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/dev/stdin); } 'hi'
 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-



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.


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.



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 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 $({}/dev/stdin); } 'hi'
hi
 ~ $ { echo $(11/dev/stdin); } 'hi'
hi

That one really is ignored. No variable named xxx... is actually set.
-- 
Dan Douglas

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