frankc frankc - 2 years ago 128
Linux Question

How can I make the watch command interpret vt100 sequences?

Consider this simple example (which displays in red):

echo -e "\033[31mHello World\033[0m"

It displays on the terminal correctly in red. Now consider:

watch echo -e "\033[31mHello World\033[0m"

It does not display the color.

Note: I am aware that it is easy to write a loop that mimics the basic behavior by clearing and rerunning. However, the clear operation causes the screen to flash, which does not happen under watch

EDIT: Originally this question specified escape sequences rather than vt100 sequences, but that is not really what I am after, and was solved with single quotes.

Answer Source


More recent versions of watch support color. You will need to use an extra level of quoting to preserve the quotes and escapes in the particular situation of the example in the question:

watch 'echo -e "\033[31mHello World\033[0m"'

From man watch:

  -c, --color
          Interpret ANSI color sequences.


From man watch:

Non-printing characters are stripped from program output. Use "cat -v" as part of the command pipeline if you want to see them.

But they don't get interpreted, so I don't think there's any way.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download