[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] errexit and attempting to change readonly functions
From: |
Eric Blake |
Subject: |
Re: [Help-bash] errexit and attempting to change readonly functions |
Date: |
Fri, 27 Sep 2019 16:16:29 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 |
On 9/27/19 3:43 PM, Greg Wooledge wrote:
On Fri, Sep 27, 2019 at 09:28:24PM +0100, Stephane Chazelas wrote:
It seems as if bash tried to avoid triggering errexit when it
can get away (wrt posix conformance) with not to.
The man page says,
Exit immediately if a pipeline (which may consist of a
single simple command), a list, or a compound command
(see SHELL GRAMMAR above), exits with a non-zero status.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set
"When this option is on, when any command fails... with the following
exceptions:"
and does not list an exception for functions, and the grammar definition
of command is:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02
command : simple_command
| compound_command
| compound_command redirect_list
| function_definition
;
Since function_definition _is_ a command (albeit neither a simple
command nor compound command), failure to define a function SHOULD cause
errexit behavior, when none of the other exceptions apply.
I don't see function declarations included under "compound command"
in that section. So the question, for me, is whether a function
declaration counts as a pipeline, a list, or a compound command (or
none of the above).
A pipeline is a sequence of commands.
I'm about 90% sure it doesn't count as a compound command, since
the grammar for a function declaration includes "compound-command"
right after the "()" part. Not sure about pipeline/list.
Correct about it not being a compound command. Incorrect about it not
being [part of] a list (and thus part of a pipeline), as I can do:
condition && func() { :; }
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org