tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Coming changes to /bin/sh
Date: Wed, 3 May 2017 17:38:38 +0000 (UTC)
From: christos%astron.com@localhost (Christos Zoulas)
Message-ID: <oed4iu$irv$1%blaine.gmane.org@localhost>
| Go for it (;& and LINENO) and not bother to add the bash extension for now!
I will do ;& soon (that is non-controversial I think) and if we decide
on the bash extension it can get added later. (These changes are all
really quite small.)
I just fixed the heredoc line counting bug that was part of the LINENO
changes, but I want to do a little more testing before I'm really happy
with the rest of those mods (there are just so many weird cases to get right.)
Of course, it really cannot be worse than it is now, as everything that
works now is planned to keep working using the same mechanism.
Another change I'd like to make (truly trivial to make the change) is to
implement actual POSIX syntax for pipelines, which permits a "!' reserved
word only before a pipeline, and nowhere else.
Note, this does not prevent stuff like
! false
there "false" is just a degenerate pipeline.
What would be affected is nonsense like
command | ! other-command | ...
The exit status (which is all "!" affects) of commands in a pipe, other than
the final one, is not used, so the "!" is useless - but that it can be
used, and that the status we care about is the last command, suggests that
perhaps the correct syntax is
command | command | ! last-command
if we want to invert the last command status, and hence the pipe status.
It isn't, that is what
! command | command | last-command
does. The "!" applies to the pipeline (it binds with lower precedence than |)
and inverts the pipeline exit status (which is derived from the last-command
exit status.)
Does anyone have any objections to that? (For now, I will just #if 0
the code that permits the stray !'s so it would be trivial to replace
later if desired.) (I have already done this in my provate copy, and
it all seems fine to me, but there are lots of really wierd scripts out there.)
Note that bash has a "pipefail" option, that allows it to derive exit status
of a pipeline from that of all of the commands in the pipe - if any return
"failure" (non-zero) and this option is set, then the pipeline returns non-zero
(how it actually works out what non-zero value to use I have no idea.)
With an option like that (which we do not have, and is not in POSIX) allowing
! on the individual commands makes more sense, but the syntax do do it cleanly
is ugly.
When considering this, note that if you *really* believe you need to
negate the status of a command in a pipe, you can do it in a way where
the syntax is defined and understandable, using something like
command | { ! bad-command ; } | more-commands
The {} there act as parentheses, to bind the ! to the pipeline that is
"bad-command" here, which is just one element of the outer pipeline.
That will continue to work (that is standard POSIX syntax.)
kre
Home |
Main Index |
Thread Index |
Old Index