On 01/09/2021 18:48, Robert Elz via austin-group-l at The Open Group wrote:
Date: Wed, 1 Sep 2021 16:38:00 +0300 From: "=?UTF-8?B?T8SfdXo=?= via austin-group-l at The Open Group" <[email protected]> Message-ID: <cah7i3lpfk0tfxwpqny3ma6hzmptsqvsysq5nfzfxetr7yeq...@mail.gmail.com>| true | a=$? b=`exit 1` b=$? >`echo /dev/null; exit 2` | echo $? $a $b | Now, I wonder, what did I miss? That $? (the exit status) is defined only when a command completes. What it is in the middle of a command execution isn't specified.
$? is defined as "Expands to the decimal exit status of the most recent pipeline (see Pipelines)." During the a=$? and b=$? assignments, the most recent pipeline in that shell execution environment was 'true' at line 1. Is there any statement that overrides the general definition to explicitly make this unspecified? If not, the general definition applies and $? must expand to 0 both times it appears on line 2.
Cheers, Harald van Dijk
