[TriLUG] colorize stderr in bash

Alan Porter porter at trilug.org
Wed Jul 23 17:49:10 EDT 2008


> I wonder if there's a way to pipe stderr to a program that adds
> escape sequences and sends it right back to stderr while
> leaving stdout intact.
>   

In short, this is not going to work.

STDERR and STDOUT are going to be mixed onto the same terminal, not
following any clean pattern.  Even if you went so far as to change the
color before and after every character in STDOUT, you'd still have problems.

For example, if you did [red]$CHAR[white] for all characters in STDOUT,
it might still get mixed like this:

some stderr: [red]A[white][red]B[white][red]C
<interrupted>
some stdout: XYZ
<back>
[white][red]D[white][red]E[white]


You would need some way to tell the terminal how to combine the two
streams in an orderly way.


Alan





.




More information about the TriLUG mailing list