Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11539

local keyword hides return code of command substitution

From idallen@home.idallen.ca
Newsgroups gnu.bash.bug
Subject local keyword hides return code of command substitution
Date 2015-09-22 10:19 -0400
Message-ID <mailman.1598.1442934969.19560.bug-bash@gnu.org> (permalink)

Show all headers | View raw


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 - idallen@idallen.ca - www.idallen.com
Myfunc () {
    foo=$( false )
    echo "return code should be 1: $?"
    local bar=$( false )
    echo "return code should be 1: $?"
}
Myfunc

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

local keyword hides return code of command substitution idallen@home.idallen.ca - 2015-09-22 10:19 -0400

csiph-web