Robert Elz <k...@munnari.oz.au> wrote, on 07 Sep 2018: > > [...] in the NetBSD man page description of pipefail we handle the > exit status issue (with/without pipefail, with/without !) a little > differently. > Our text defines a pipestatus for a pipeline, which is the thing that > pipefail controls, and then derives the exit status of a pipeline from > the pipestatus of that pipeline based upon the presence, or not, of > the ! word. The effect is the same as the big table, but it is rather > more concise.
I looked at the text on netbsd.gw.com/cgi-bin/man-cgi?sh++NetBSD-current and I do not think it could easily be adapted for use in the standard. The main problem is that it considers the '!' not to be part of the "pipeline" that has a "pipeline status". In POSIX the '!' is part of the pipeline, so if we were to use the term "pipeline status" as it is used in the NetBSD text, the term itself would be misleading. [...] > I am not sure what the attitude is here to creating new special parameters, > the ones we have all seem to have originated in the original Bourne shell, > and no-one has ever added anything new (I actually had $+ for a short > while - never released anywhere - which was a comlpement to $- and > contained the single letter options that were not set ... more for symmetry > than to solve any real problem ... so it went away again). > > But if anything cries out for a new special parameter it would be this - to > make the exit status of the processes that form a pipeline available. We would need it to be implemented in at least one widely-used shell before we could consider standardising it. > If I had to pick something, I'd use $| and define it to be the a space > separated list of exit status values ($?) for the commands that form a > pipeline. It would be set (and have a lifetime) exactly the same as > applies to $? - and in the case of a degenerate pipeline (a pipeline > with no pipe operators, ie: a simple command), $| and $? would be > identical (as they would be before any command had run.) Using the character '|' is problematic because it is an operator. The only way to access the parameter would be to put it in double quotes. So to access the status of, say, the second command in the pipeline you would have to do: statuses="$|" set -- $statuses status2=$2 instead of just: set -- $| status2=$2 (the latter would be equivalent to: set -- $ | status2=$2) -- Geoff Clare <g.cl...@opengroup.org> The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England