Description
POSIX defines the value of special parameter ?
as follows:
Expands to the shortest representation of the decimal exit status (see 2.8.2 Exit Status for Commands) of the pipeline (see 2.9.2 Pipelines) executed from the current shell execution environment (not a subshell environment) that most recently either terminated or, optionally but only if the shell is interactive and job control is enabled, was stopped by a signal. If this pipeline terminated, the status value shall be its exit status; otherwise, the status value shall be the same as the exit status that would have resulted if the pipeline had been terminated by a signal with the same number as the signal that stopped it. The value of the special parameter '?' shall be set to 0 during initialization of the shell. When a subshell environment is created, the value of the special parameter '?' from the invoking shell environment shall be preserved in the subshell.
Currently, when a foreground job stops, yash sets ?
to the exit status indicating the signal that stopped the job. This is not compliant with the standard if the shell is not interactive. To comply with the standard, the exit status should reflect the signal in interactive shells only.
Considerations
- If the suspension of the job is not reflected in parameter
?
, the user may be confused when they check the exit status of the last command. Especially, if the shell is not interactive, there is no way to know that the job was suspended. This renders the job control feature useless in non-interactive shells. Why should we bother to follow the standard then? See also Ignore remaining commands after a foreground job stops yash-rs#478 for the discussion on the behavior of job control in non-interactive shells.