Whenever I use grep
, and I pipe it to an other program, the --color
option is not respected. I know I could use --color=always
, but It also comes up with some other commands that I would like to get the exact output of that command as the output I would get if I was in a tty.
So my question is, is it possible to trick a command into thinking that the command is run inside a tty ?
For example, running
grep --color word file # Outputs some colors
grep --color word file | cat # Doesn't output any colors
I'd like to be able to write something like :
IS_TTY=TRUE grep --color word file | cat # Outputs some colors
This question seems to have a tool that might do what I want :empty - run processes and applications under pseudo-terminal (PTY), but from what I could read in the docs, I'm not sure it can help for my problem
--color
changes the actual data stream that is sent to command further down the pipeline? The consequence would be breaking other-wise reasonable code becausesearchTarget
is not^[32;4gsearchTarget^[32;h
(or similar). Good luck.ag
, the silversearcher, but also mocha, ...) and I don't have time to learn all the options to print with the same format whenever I pipe those commands into others)[linux] (or) [bash] --color
? Good luck.