If I type:
progA | progB && progC
then progC is conditional on progB, and not on progA. Is there a way to both pipe the output of progA to progB, and then, after progA is done (and if I have to wait for progB to be done too, then that’s not a problem) have progC be conditional on prog A?
Also, I need to keep the pipe — as in I can’t afford to do progA > file; ....; progB < file and loose the time efficiency.
EDIT: How to use the return code of the first program in a pipe command line is a similar question, but does not have constraint of keeping the pipe, and it also assumes that I have access to the code of progB.
Use a named pipe.
With variations on
grepasprogAandcatasprogB:Note that
waitwithout a job ID will always return0no matter what the exit status of the background job was and thatwait %1in a separate command will not work when the job exits before you start thewait. I wouldn’t want to put this into production really. All this was tested onbashbtw and might be slightly different for other shells.