De stackoverflow - na detecção de tty :
Most commands that do print out those color codes explicitly check if stdout/stderr is a tty (using the isatty command).
De stackoverflow - na captura de saída colorida :
One way to capture colorized output is with the
script
command. Runningscript
will start a bash session where all of the raw output is captured to a file (named typescript by default).
Veja man script
para mais informações.