[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: exit status when setting local variables
From: |
Chet Ramey |
Subject: |
Re: exit status when setting local variables |
Date: |
Mon, 27 Mar 2006 14:50:20 -0500 |
User-agent: |
Thunderbird 1.5 (Macintosh/20051201) |
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 chet@case.edu http://cnswww.cns.cwru.edu/~chet/