In my script, I am using the ifne
utility from the moreutils
package. The line can be simplified to the following:
printf "asdf\n" | ifne cat - && echo "stream not empty"
ifne
executes only if the stream is non-empty. But how can I make the second command (echo "stream not empty"
) also execute only if the stream is non-empty? For example, how can change the following command so that it doesn't print "stream not empty"?
printf "" | ifne cat - && echo "stream not empty"
Surrounding cat
and echo
with parentheses generates a syntax error:
printf "" | ifne (cat - && echo "stream not empty")
How can I execute the last command only if stream is non-empty?
Write error
bytee
if the output is large or slow enough asecho
(here a standaloneecho
executable), will exit immediately without reading its input, sopee
will soon see a broken pipe. – Stéphane Chazelas Apr 20 '21 at 06:44