From owner-freebsd-current@FreeBSD.ORG Thu Nov 6 17:32:05 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3F1ECE3D for ; Thu, 6 Nov 2014 17:32:05 +0000 (UTC) Received: from smtp.vangyzen.net (hotblack.vangyzen.net [199.48.133.146]) by mx1.freebsd.org (Postfix) with ESMTP id 22891E3C for ; Thu, 6 Nov 2014 17:32:04 +0000 (UTC) Received: from marvin.lab.vangyzen.net (c-24-125-214-90.hsd1.va.comcast.net [24.125.214.90]) by smtp.vangyzen.net (Postfix) with ESMTPSA id 195FD56467; Thu, 6 Nov 2014 11:31:58 -0600 (CST) Message-ID: <545BB08D.4020402@vangyzen.net> Date: Thu, 06 Nov 2014 12:31:57 -0500 From: Eric van Gyzen User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Fabian Keil Subject: Re: sh: "local" assignment from command loses exit status References: <545BADDE.5050605@vangyzen.net> <74dd7d12.793ea654@fabiankeil.de> In-Reply-To: <74dd7d12.793ea654@fabiankeil.de> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: Freebsd current X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Nov 2014 17:32:05 -0000 On 11/06/2014 12:30, Fabian Keil wrote: > Eric van Gyzen wrote: > >> In sh, if I use a single statement to declare a local variable and >> assign the output of a command to it, the exit status of that command is >> lost. For example: >> >> should_return_false() { >> local var1=`false` >> } >> >> The function should return non-zero, but it returns zero. > The function should return the return code of the last command. > In your example, the last command is "local". Fair enough. What about errexit? The shell ran a command whose exit status was not tested, that status was failure, yet the shell did not exit. Eric