I would like to be able to pipe all bash terminal commands through a certain command (for no good reason other than to play a prank on someone). I just want to pipe the stdout of any executed command into a predetermined program without doing anything special.
For example:
If that predetermined program was cowsay
echo "Hello World"
should output
_____________
< Hello World >
-------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
How can I achieve this? (Some of the fun programs I'd like to use to play pranks on others include rev
, cowsay
, and lolcat
)
Where
COMMAND
isrev
,lolcat
or other. This won't work withcowsay
.E.g.
Explanation:
exec
normally replaces the current shell with another process, but if you just give it a redirection like in this case, the redirection will take place for the current shell.>
redirect stdout>(COMMAND)
input intoCOMMAND
Note that if you have a
PROMPT_COMMAND
, you should direct it to stderr to avoid the redirected stdout.