> On Feb 2, 2021, at 11:52 AM, Kevin Buchs <kevin.bu...@gmail.com> wrote: > > Browsing around bashref, I found the lastpipe option and I tried it, but > it seemed to have no effect. > > Rather than just submit a bug report, I thought I would try to dig in and > find the problem and try to fix it. When I downloaded the full bash source, > then I found in NEWS or CHANGES, that lastpipe was only available if job > control was disabled. Simplest case, just needed a documentation update.
The bash manual does mention this restriction: lastpipe If set, and job control is not active, the shell runs the last command of a pipeline not executed in the background in the current shell environment. (https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) > But, I looked into that further and found the conditional in execute_cmd.c > which applies the restriction. Finding nothing else about that restriction, > I decided to try removing it. I found that the full test suite still > passed. My additional testing showed no flaws. > > Of course, removing this restriction opens up the possibility that a user > can shoot themselves by trying to use job control at the same time. I think > that is a pretty rare case where one would want to do that, like, close to > never. I cannot believe even wanting to use job control with a non-lastpipe > pipeline is often done. It seems like the reward of having the feature > available for all interactive users is greater than the risk of someone > shooting themselves in the foot. Here is Chet's response to a similar request nearly four years ago (https://lists.gnu.org/archive/html/bug-bash/2017-03/msg00197.html): > From: Chet Ramey <chet.ra...@case.edu> > Subject: Re: The lastpipe shell option even with job control? > Date: March 28, 2017 at 10:17:54 AM EDT > To: "Dr. Werner Fink" <wer...@suse.de>, bug-bash@gnu.org > Cc: chet.ra...@case.edu > Reply-To: chet.ra...@case.edu > > On 3/27/17 9:44 AM, Dr. Werner Fink wrote: >> Hi, >> >> I'd like to ask if there is crucial reason, beside the correct foreground >> process group, not to allow the lastpipe shell option for an interactive >> bash? Maybe something like in the attachment could be an option? > > Yes, there is. Once you decide you're going to allow lastpipe when job > control is enabled, you commit to handling ^Z and allowing the user to > suspend that pipeline. You have to do something with the foreground > shell at that point. An interactive shell is already ignoring SIGTSTP, > so you'll have to undo that, set a handler, figure out where you are, > and decide what to do. > > Some other shells attempt to solve the problem by forking (from the > TSTP handler??) cleaning up all the state, juggling the jobs table and > process status, and letting the forked shell continue with the pipeline, > but that's really fragile and I've never been tempted to implement it. > > Chet > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > ``Ars longa, vita brevis'' - Hippocrates > Chet Ramey, UTech, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/ -- vq