I believe some commands are smart enough NOT to output color if they detect that they are writing to a pipe or a file instead of to the console, since that could ruin the parsing of their output by the next program in the pipeline.
You can try forcing the programs into outputting color with their respective flags (e.g. --color
or whatever), but it's ultimately implementation dependent if they'll honor your request or not.
GNU grep 2.27, for example, will not output color into less
even when passing --color
to it. But if you pass --color=always
and pipe it into less
, you'll be able to see the color escape codes through less
. And then, using the -R
flag will have less
interpret the color escape codes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…