bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cannot catch returncode if assigning local variables in functions


From: Bastian Bittorf
Subject: cannot catch returncode if assigning local variables in functions
Date: Sat, 20 Jun 2009 15:27:18 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2 -Wall
uname output: Linux bastian-laptop 2.6.28-13-generic #44-Ubuntu SMP Tue Jun 2 
07:57:31 UTC 2009 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.2
Patch Level: 48
Release Status: release

Description:

        when assigning local variables in functions,
        you cannot use the returncode which is generated
        for quick branching with '||' or '&&'


Repeat-By:

        myfunc()
        {
                local VAR="$( false )" || {
                        echo "error"
                        return 1
                }

                echo "fine"
        }


        in this example "error" is never reached,
        although 'false' should enforce that. workaround
        ist to first init and then assign, like this:

        local VAR
        VAR="$( false )" || {
                ...
        }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]