Is there a way to pipe the output of one function to another, but only if there is an output?
|
feedback
|
|
The following
Design notes:
If you don't mind storing the whole intermediate data in memory, here is a very slightly simpler implementation of
Here is a slightly simpler implementation with the following caveats:
Again, the whole data is stored in memory.
| |||
|
feedback
|
|
Instead of
Or you could make it more general purpose by changing it to accept the receiving program as an argument as in Gilles' answer:
| ||||
|
feedback
|
|
ifne(1) from moreutils does exactly that. Moreutils is available as a package at least in Debian and Ubuntu, probably in other distros as well. | |||
|
feedback
|
|
At least something like this works:
Please note that the above will consider line feeds and other special characters as output, so an empty line passed to that if statement will be considered as an output. Just raise the -gt limit if your output should usually be higher than 1 byte :) | |||||||||
|
feedback
|