exit status when setting local variables

2006-03-27 Thread Mike Frysinger
not sure if this is a bug or feature ... take this little snippet:
testit() {
local foo=$(false) ; echo $?
foo=$(false) ; echo $?
}

when we run the code, the output is:
0
1

rather than intuitive:
1
1
-mike


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


Re: exit status when setting local variables

2006-03-27 Thread Chet Ramey
Mike Frysinger wrote:
 not sure if this is a bug or feature ... take this little snippet:
 testit() {
   local foo=$(false) ; echo $?
   foo=$(false) ; echo $?
 }
 
 when we run the code, the output is:
 0
 1
 
 rather than intuitive:
 1
 1

It's intentional.

`local' returns success if the variable is correctly assigned a value
(for instance, the variable is not read-only).  The assignment statement
returns failure because that's how POSIX says assignment statements
behave.  (export and readonly behave the same way as local.)

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
   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