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

2

5

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?

Clinker answered 23/7, 2015 at 15:9 Comment(0)
O
5

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'
Ollayos answered 23/7, 2015 at 15:15 Comment(0)
T
2

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

$ watch "fortune | cowsay"
Tommy answered 23/7, 2015 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.