Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 4
    It might be a bug that a program produces colored output even then it's output is redirected to a file and doesn't provide an option to switch it off. I'd expect any program that colors it's output to check isatty(stdin) before doing so. Mind to share what is that program? Commented Dec 4, 2010 at 6:44
  • pass it through cat - quick test I ran grep --color=auto myusername /etc/passwd gives me my username in red with white text elsewhree. grep --color=auto myusername /etc/passwd | cat gives me plain white text Commented Nov 15, 2017 at 2:48
  • 3
    That's not a solution. It only works because grep --color=auto avoids producing colored output when standard output is not a terminal. I'm talking about a command that unconditionally outputs color codes. (As alex points out above, such behavior is arguably a bug, but sometimes we need to work with imperfect software that we can't easily fix ourselves, and that's what this question is about.) Commented Nov 15, 2017 at 4:00
  • Possibly relevant unix.stackexchange.com/questions/14684/… Commented Jun 10, 2018 at 14:22
  • Reinforcing Ryan's post: grep --colour=always myusername /etc/passwd | cat keeps the username in red. Commented Aug 25, 2022 at 8:36