How to correctly pipe output into “say” in terminal

command lineterminal

I realized that the say command can be great when combined with another command/program because it can read you the output. I tried to pipe the output from leave to say by typing the following in terminal, but it didn't work.

leave +5 | say

What is the correct way to do this?

Best Answer

Based on mankoff's answer, this works:

leave +1 2>&1 | while read line ; do echo $line | say ; done

although leave no longer vanishes into the background and lets you carry on typing. Similarly:

leave +1 2>&1 | while read line ; do echo $line | say ; done &

will make it vanish into the background, but will also speak a (harmless) process ID number as well. So neither is quite perfect, but both work.

(I was looking for a solution to:

ping google.com | say

which suffers a similar problem, and someone suggested the above as a solution. I didn't add this as a comment to mankoff's answer because I can't work out how to put spaces and newlines in comments.).