Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why doesn't watch work when piping the output of fortune into cowsay

cowsay is a silly linux tool for displaying a cow saying given text in the terminal.

$ cowsay hello

fortune is a silly linux too for displaying a "random" quote in the terminal.

$ fortune

Both of these commands can be repeatedly ran in the terminal using watch e.g.

$ watch cowsay hello
$ watch fortune

Additionally these two commands can be combined so the cow says "random" quotes. By piping the output of fortune into cowsay.

$ fortune | cowsay

However a combination of the use of watch and piping the output of fortune into cowsay doesn't do anything.... i.e. hangs until the process is ended

$ watch fortune | cowsay

Does anyone know why?

like image 442
Andy T Avatar asked Jul 23 '15 15:07

Andy T


People also ask

What is Cowsay command?

cowsay is a program that generates ASCII art pictures of a cow with a message. It can also generate pictures using pre-made images of other animals, such as Tux the Penguin, the Linux mascot. It is written in Perl.


2 Answers

With watch fortune | cowsay you are piping the output of watch fortune into cowsay. You want to watch the value of fortune piped to cowsay so you should quote it so watch will get the whole command to execute as

watch 'fortune | cowsay'
like image 150
Eric Renouf Avatar answered Oct 19 '22 11:10

Eric Renouf


This is because everything after | is executed in a subshell. Try this:

$ watch "fortune | cowsay"
like image 23
Arkadiusz Drabczyk Avatar answered Oct 19 '22 11:10

Arkadiusz Drabczyk