Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../. -I.././include -I.././lib -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall uname output: Linux idallen-oak 3.19.0-28-generic #30-Ubuntu SMP Mon Aug 31 15:52:51 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu
Bash Version: 4.3 Patch Level: 30 Release Status: release Description: Adding a "local" keyword to a variable assignment hides the return code of a command substitution. Same problem in both bash and dash shells. The keyword may be operating as described in the man page, but it is highly non-intuitive that adding it would do this. The work-around is to use "local" to declare the variable first, then do the command substitution assignment on another line and check the return code there. If the behaviour of "local" can't be changed, perhaps the man page could warn about this? Repeat-By: Run this: #!/bin/bash -u # Using "local" keyword hides return code of command substitution. # Same problem in both bash and dash shells. # -Ian! D. Allen - idal...@idallen.ca - www.idallen.com Myfunc () { foo=$( false ) echo "return code should be 1: $?" local bar=$( false ) echo "return code should be 1: $?" } Myfunc