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" 
<austin-group-l@opengroup.org>
     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

  • $? in a simple comman... Oğuz via austin-group-l at The Open Group
    • Re: $? in a simp... Harald van Dijk via austin-group-l at The Open Group
      • Re: $? in a ... Geoff Clare via austin-group-l at The Open Group
        • Re: $? i... Harald van Dijk via austin-group-l at The Open Group
    • Re: $? in a simp... Robert Elz via austin-group-l at The Open Group
      • Re: $? in a ... Oğuz via austin-group-l at The Open Group
      • Re: $? in a ... Harald van Dijk via austin-group-l at The Open Group
      • Re: $? in a ... Robert Elz via austin-group-l at The Open Group
        • Re: $? i... Chet Ramey via austin-group-l at The Open Group
          • Re: ... Joerg Schilling via austin-group-l at The Open Group
            • ... Scott Lurndal via austin-group-l at The Open Group
              • ... Joerg Schilling via austin-group-l at The Open Group
            • ... Chet Ramey via austin-group-l at The Open Group
      • Re: $? in a ... Robert Elz via austin-group-l at The Open Group

Reply via email to