foo | bar > out.txt would normally save the output to
foo fails, then clearly
bar cannot have any output, so it makes no sense to create
out.txt. However, usually the result is that when
foo fails an empty
out.txt gets created.
I use this type of command often in Makefiles where the problem gets compounded: Once you create the empty file, the
make command stops working, because make sees the empty file and decides it's not necessary to create it again.
Is there a way to make
out.txt not get created if the pipeline never reaches bar?