2

I'm looking for a method to have bash colorize the output from a command based on what stream it was written to the terminal from. Is there any way to get it to colorize per stream?

Like for example

stdout -> regular color
stderr -> red
program created streams that write to the terminal -> blue
0

2 Answers 2

0

While not identical to your requirements, this earlier question would be worth a read, where someone wanted to differentiate stdout/stderr by color.

How to set font color for STDOUT and STDERR

0

There's:

https://github.com/sickill/stderred

or you can do it from bash with something like:

rederror() { (tput setaf 1; cat ; tput sgr0) >&2; }
#Example
someCommand() { echo normal; echo error >&2; }
someCommand 2> >( rederror )

I don't think you can color non-stdout streat that go to the terminal blue from bash. It should be possible with that approach that stderred is using (but I think it only colors stderr).

1
  • The rederror does not seem to work with any consistency. I wrote a short cpp program that writes out on the various streams avaible to it using differint methods and testing it several times there was varying results. gist Commented Jul 28, 2015 at 21:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.