LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to "echo" coloured text? (https://www.linuxquestions.org/questions/linux-general-1/how-to-echo-coloured-text-368724/)

kornerr 10-01-2005 09:09 AM

How to "echo" coloured text?
 
Thanks.

druuna 10-01-2005 09:45 AM

Hi,

Code:

#!/bin/bash

# Escape code
esc=`echo -en "\033"`

# Set colors
cc_red="${esc}[0;31m"
cc_green="${esc}[0;32m"
cc_yellow="${esc}[0;33m"
cc_blue="${esc}[0;34m"
cc_normal=`echo -en "${esc}[m\017"`

echo "Here's ${cc_green}some green text${cc_normal} for you."
echo "Here's ${cc_blue}some green text${cc_normal} for you."

The color codes (0;31 etc) are like those used in dir_colors:

# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white

Hope this helps.

kornerr 10-01-2005 10:00 AM

Thanks, druuna!

Now I'm able to add coloured echo "Compilation succeeded!" to Makefiles :)


All times are GMT -5. The time now is 04:16 AM.