Re: set -e not ignored in AND-OR list
Harald van Dijk <[email protected]> Sun, 24 Nov 2024 15:15:49 +0000
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
On 24/11/2024 11:58, Herbert Xu wrote:
> On Sat, Nov 23, 2024 at 04:22:52AM +0100, Christoph Anton Mitterer wrote:
>>
>> @Herbert, you've said that you believe dash's behaviour is POSIX
>> compliant.
>> But I still couldn't find anything in the text which would imply
>> this... and Harald who typically knows things quite well also seems to
>> believe that POSIX doesn't allow it.
>
> It's simple really, POSIX says:
>
> or any command of an AND-OR list other than the last.
>
> The word "command" refers to the commands that make up the AND-OR
> list. Command substitution is not part of that at all.
Isn't it? Taking the rest of the sentence along with it:
The -e setting shall be ignored when executing [...] any command of an
AND-OR list other than the last.
So, given
set -e
test -n "$(false; echo x)" && echo x
the -e setting shall be ignored when executing
test -n "$(false; echo x)"
That much I think is not in doubt.
What does it mean for that command to be executed? 2.9.1.1 Order of
Processing says:
When a given simple command is required to be executed (that is, when
any conditional construct such as an AND-OR list or a case statement
has not bypassed the simple command), the following expansions,
assignments, and redirections shall all be performed from the
beginning of the command text to the end:
[...]
2. [...] For all other command names, words after the word that
produced the command name shall be subject only to regular
expansion.
[...]
That is, the expansion of words in a simple command is considered part
of the execution of that command. When the "false; echo x" is being
executed, this is part of the execution of test -n "$(false; echo x)".
Because that test -n "$(false; echo x)" command is being executed, and
it is a command of an AND-OR list other than the last, by what POSIX
says, the set -e setting shall be ignored.
Cheers,
Harald van Dijk