There are various situations in which one wants to crank up later parts
of a pipeline only if the earlier parts produce any output. The sort of
situation I have in mind is
some_command some_arguments 2>&1 | mailx -s "Output of some_command" fall_guy
where one wants no message to be sent in the (common) case when some_command
generates no output. The solution ought to be along the lines of
some_command some_arguments 2>&1 | \
obey_if_stdin_nonempty 'mailx -s "Output of some_command" fall_guy'
where your task for today is to implement obey_if_stdin_nonempty.
It's easy enough to write a C or Perl program to do this (though not so easy
to have obey_if_stdin_nonempty actually excise itself from the pipeline
after it has fired up its target command). But I feel there really ought
to be a simple way to do this by using, or misusing, something out of the
standard Unix toolbox. Any thoughts?