I have a script that uses escape codes to highlight text matches in its output. All is good except when the output is piped to less
, which prints the escape codes
e.g.
$ echo -e "\033[31m -- Hello World! -- \033[m"
-- Hello World! --
Piped to less
:
$ echo -e "\033[31m -- Hello World! -- \033[m" | less
ESC[31m -- Hello World! -- ESC[m
I was wondering how other tools like ls
, grep
, etc are able to output in color yet it looks fine when piped to less
?