Join GitHub today
echo "foo" >&2 is not colorized #16
After reading a lot about process file descriptors, redirection and stuff the
If you add 3rd line to your shell script:
and run it you'll see that "lolza" is printed correctly in red. But it didn't
Because echo always writes to FD 1.
So echo writes to FD 1 and stderr checks if process is writing to FD 2. And
See here for more info about the topic:
One solution I was evaluating was not to check if process is writing to FD with the number "2" but instead check if underlying file description structure is the same for FD 2 and FD to which process is writing. I tried that but it doesn't work properly because by default every process has both FD 1 and FD 2 connected to the same /dev/pts/X file (where X is number) resulting in ALL text (stdout also) being colorized.
I have some thoughts about this:
That's why in this case echo >&2 doesn't work.
I'm written terminals myself, here is why I thinks we HAVE TO use the same file for both stdout and stderr: if we use the different one, we can't properly display them to the screen.
I know how to solve this on windows(which I use before I bought this MACBook Pro), but I'm new to OSX programming, so I'm unable to come with actual OSX code(not yet) even I know how to solve the problem. It involves the following: multi-threading, with blocking IO and message passing, IO redirection.
Hope to see this feature soon.