Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Robert Elz Newsgroups: gnu.bash.bug Subject: Re: local failure Date: Sun, 31 May 2020 23:21:21 +0700 Lines: 99 Approved: bug-bash@gnu.org Message-ID: References: <87tuzzh34x.fsf@hobgoblin.ariadne.com> <11340.1590942081@jinx.noi.kre.to> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1590943019 25505 209.51.188.17 (31 May 2020 16:36:59 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org, "bash@packages.debian.org" To: Laurent Picquet Envelope-to: bug-bash@gnu.org In-Reply-To: Received-SPF: permerror client-ip=2001:3c8:9009:181::2; envelope-from=kre@munnari.OZ.AU; helo=munnari.OZ.AU X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, T_SPF_HELO_PERMERROR=0.01, T_SPF_PERMERROR=0.01 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <11340.1590942081@jinx.noi.kre.to> X-Mailman-Original-References: <87tuzzh34x.fsf@hobgoblin.ariadne.com> Xref: csiph.com gnu.bash.bug:16330 Date: Sun, 31 May 2020 10:29:27 +0100 From: Laurent Picquet Message-ID: =7C This behaviour is not fully documented Nothing is ever =22fully=22 documented, as it is always possible to write even more text about anything at all - and if that were done then it is clear that what existed before was not =22full=22. So, instead of =22fully documented=22 let's use =22adequately documented= =22 and for that it is. But you do need to understand how things fit together to follow. First, the exit status is only ever set as the result of executing a command - and only a command in the current execution environment. ? Expands to the exit status of the most recently executed foreground pipeline. =5Belsewhere it is noted that a simple command is a degenerate pipeline, so is a compound command for that matter.=5D =22local=22 is such a command, and like all such commands, its exit statu= s is documented... The return status is 0 unless local is used outside a function, an invalid name is supplied, or name is a readonly variable. (that text has been previously quoted in this thread). Command substitutions execute in a different shell execution environment (nothing that happens in one has any effect upon the shell that contains them - except that stdout from the command substitution is inserted into the current command line (and then potentially subject to field splitting= , pathname expansion, ...) -- it becomes a part of some other command. There is one exception to the case that only commands in the current execution environment ever set the exit status, which is documented in bash(1) as ... If there is a command name left after expansion, execution proceed= s as described below. Otherwise, the command exits. If one of the expansions contained a command substitution, the exit status of th= e command is the exit status of the last command substitution perfor= med. If there were no command substitutions, the command exits with a s= tatus of zero. None that neither redirects nor variable assignments are commands (but almost everything else that you would write in a sh script is, including =22local=22). The =22as described below=22 involves locating the comman= d, running it, and obtaining its exit status - and is what is done when there is a command. When there isn't - which is what happens when all there was was variable assignments &/or redirects - then, and only then, does the: If one of the expansions contained a command substitution, the exit status of the command is the exit status of the last command= substitution performed. This is the only way that the exit status of a command substitution can ever be observed in the parent shell. But you have to read the entire man page to observe that nowhere else is the status of a command substitu= tion ever reported. So, the doc is all there, and it is possible to work out what happens. As above, it is always possible to write more - but write too much, and instead of a manual page, what would be left would be a tutorial, or perh= aps even a book (but there's already one, perhaps more than one, of those). There is certainly nothing special about the local command in this contex= t, any command where there happens to be a command substitution on the comma= nd line somewhere works exactly the same way, so it would be wrong to make a= ny special note of this in the doc for =22local=22 without also putting the = same extra info in the descriptions of every other command. kre