LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   bash coloring output (http://www.linuxquestions.org/questions/programming-9/bash-coloring-output-896668/)

Jerry Mcguire 08-11-2011 01:17 AM

bash coloring output
 
Hi,

I want to `cat` any text file to screen with alternate text color for the alternate lines. Is there any simple command to do that in bash?

e.g.
Code:

$ cat /etc/hosts | coloring.sh
Also, how does a bash script accepting pipe input know when to stop? Thanks.

J.

Jerry Mcguire 08-11-2011 01:44 AM

Thanks. I got it.

http://www.linuxquestions.org/questi...mostly-229142/

Code:

#!sh
i=0
while read line
do
  if [ "$i" -eq "0" ]
  then
                echo -e "\e[1;34m${line}\e[0m"
                i=1
  else
                echo -e "\e[1;31m${line}\e[0m"
                i=0
  fi
done
exit 0



All times are GMT -5. The time now is 09:45 AM.