The situation I have in mind has the following structure:
% some_command | [PRODUCED OUTPUT] || echo 'no output' >&2
Here [PRODUCED OUTPUT]
stands for some as-yet-unspecified testing command, whose value should be true
(i.e. "success") iff some_command
produces any output at all.
Of course, some_command
stands for an arbitrarily complex pipeline, and likewise, echo 'no output' >&2
stands for some arbitrary action to perform in case some_command
produces no output.
Is there a standard test to do the job represented above by [PRODUCED OUTPUT]
? grep -qm1 '.'
comes close but also reports false on an input consisting of empty lines.
Unlike Check if pipe is empty and run a command on the data if it isn't I just want to discard the input if it's present, I don't need to preserve it.
| grep -q .
? O.o – muru Apr 13 '16 at 14:47grep
? – muru Apr 13 '16 at 15:01grep -q ''
, which may have been better.) – kjo Apr 14 '16 at 10:14ifne
(moreutils): runs a given command if and only if the standard input is not empty – HappyFace Sep 20 '20 at 18:51