views:

77

answers:

2

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.

+1  A: 

You can try single quoting your command :

watch 'echo -e "\tHello World"'

On my machine this leaves me with a -e as first character, and a correctly tabbed hello world. It seems -e is the default for my version of echo. Still, it is a progress toward a correctly tabbed hello world

What happens is a double unquoting :
what watch see

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

what the shell called by watch see :

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

And then the backslash come into play, even when quoted, and it becomes a quoting nightmare.

shodanex
In an attempt to simplify things, I have probably made things too simple. You are right that this works and I have upvoted you for that, but what I am really after is getting vt100 codes to work correctly, which appears to be a different problem than just getting escape sequences interpreted. For instance:echo -e "\033[31mHello World\033[0m" does not work properly under watch even with single quotes.
frankc
A: 

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.

Dennis Williamson
I'm basically convinced it's impossible.
frankc