I'm running grep
inside a bash script. If I run the grep
command directly, I see colored output of the file name and search string:
grep -i username /tmp/sess_*
If I put that command in a bash script, it works, but the colors are lost. How can I preserve the colored output?
Best Answer
You could add
--color=always
to your grep.Relevant section from my local manpage:
As this question on SO suggests, probably you have an alias for
grep
that maps it togrep --color=auto
in your.bashrc
and that isn't read by the script, and so isn't applied within the script.