In Linux, is it possible to run a pipe:cmd1 | cmd2in such a way that:cmd2 doesn't start running until cmd1 has completely finished, andIf cmd1 has an error, cmd2 doesn't run at all and the exit status of the pipe is the exit status of cmd1.To give an example, how to make this pipe:false | echo okoutput nothing and return a non-zero status?Failed Solution 1set -o pipefailThe pipe does have a non-zero exit status, but cmd2 is still run even if cmd1 fails.Failed Solution 2cmd1 && cmd2This is not a pipe. No I/O redirection.Failed Solution 3mkfifo /tmp/fifocmd1 > /tmp/fifo && cmd2 < /tmp/fifoIt blocks.Suboptimal Solutiontouch /tmp/filecmd1 > /tmp/file && cmd2 < /tmp/fileThis seems to be working. But it has several shortcomings:It writes data to disk where I/O is slower. (Surely you can use tmpfs but that's an additional system requirement).You have to choose the temporary filename carefully. Otherwise it can accidentally overwrite an existing file. mktemp may help, but an unnamed pipe saves you the naming chore entirely.The filesystem on which the temporary file resides may not be big enough to hold the entire data.The temporary file doesn't auto clean-up.
How to run a pipe safely and sequentially?
bash;pipe;fifo