[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: use local and $?
From: |
Chet Ramey |
Subject: |
Re: use local and $? |
Date: |
Mon, 12 Jan 2015 11:32:22 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 |
On 1/12/15 4:23 AM, l_j_f wrote:
> 1. bash version
> -sh-4.3# bash --version
> GNU bash, version 4.3.0(1)-release (arm-hisiv200-linux-gnu)
> Copyright (C) 2013 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
>
> This is free software; you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
>
> 2. the script
> #!/bin/bash
>
> ok() {
> echo ok
> }
>
> error() {
> echo error
> return 1
> }
>
>
> main() {
> local err
>
> local a=$(ok); err=$?
> echo a=$a err=$err
>
> local b=$(error); err=$?
> echo b=$b err=$err
> }
> main "$@"
>
> 3. the result
> -sh-4.3# ./test2.sh
> a=ok err=0
> b=error err=0 #I think it should be "b=error err=1"
This is not a bug. See the following message from two weeks ago:
http://lists.gnu.org/archive/html/bug-bash/2014-12/msg00176.html
or read the last paragraph of
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/