Possible Duplicate:
grep loses coloring when run from bash script
I have a simple bash script to print a header on top of my grep results:
#!/bin/bash
for var in "$@"
do
if [[ $var != -* ]];
then
break
fi
done
echo
echo -en "\e[1;31m ====== GREP $var ======\e[0m\n"
echo
grep $@
But the final command is somehow not the same as actually running grep from the prompt directly, because the colors are missing from the results. When executing grep directly, the results show filenames in purple and matches in red, but now all the output is the normal terminal text color. Can someone tell me how to get the colored version from my script?
Looks like grep does not produce colors when not in interactive mode. You can force it to produce colored output: