Wednesday, 20 March 2013

How to echo colored text in linux shell script:

Colored text in Linux shell script:

 

Having a colourful display on shell script is something that’d beautify your experience. Using colour text and echos will help you to highlight and distinguish the shell output on a linux prompt.

Try following command on you bash:

syntax:

echo -e "\033[COLOR1;COLOR2m sample text\033[0m"

The semicolon separated numbers "COLOR1" and "COLOR2" specify a
foreground and a background color.The order of the numbers does not
matter, since the foreground and background numbers fall in non-
overlapping ranges."m" terminates the escape sequence, and the text
begins immediately after that.Although setting the colors separately
also work (i.e. \033[44m\033[32m).


echo -e "\033[33;31m Color Text" - red

echo -e "\033[33;32m Color Text" - green

echo -e "\033[33;33m Color Text" - yellow

echo -e "\033[33;34m Color Text" - blue

echo -e "\033[33;35m Color Text" - Magenta

echo -e "\033[33;30m Color Text" - Gray

echo -e "\033[33;36m Color Text" - Cyan


Enjoy!!!

No comments:

Post a Comment