Ubuntu – How to get colored output from bash script

bash

When I execute grep from within gnome-terminal, I get colored output – easily noticeable match, line-numbers (-n) with different colors etc

But when I execute exactly same grep command through bash script I get plane output, without coloring

Is there a way I can get colored output by using bash script?

Best Answer

  • Using the --color option works for me out when I run grep inside of shell scripts.

    Here is an example of what you want.

    grep -n --color=auto "PATTERN" FILE
    
  • Related Question