Monday, April 29, 2013

Shell : using colors

Monochromatic terminal is boring : 

why not using Colors?


There is a way to color your script outputs : 

instead of using: echo "*"

use: echo -e "\033[*;*m*"

example : 
echo "hello world"  displays: hello world
&
echo -e "\033[1;31;42mhello world" displays :hello world

there is a variety of different colors of both font and background : 
echo -e "\033[0;30mGrey   0;30     \033[1;30mBold Grey    1;30"
echo -e "\033[0;31mRed    0;31     \033[1;31mBold Red     1;31"
echo -e "\033[0;32mGreen  0;32     \033[1;32mBold Green   1;32"
echo -e "\033[0;33mYellow 0;33     \033[1;33mBold Yellow  1;33"
echo -e "\033[0;34mBlue   0;34     \033[1;34mBold Blue    1;34"
echo -e "\033[0;35mPurple 0;35     \033[1;35mBold Purple  1;35"
echo -e "\033[0;36mCyan   0;36     \033[1;36mBold Cyan    1;36"
echo -e "\033[0;37mWhite  0;37     \033[1;37mBold white   1;37"


change the first number (3) by 4 (33 --> 43) to set background

to set default colors back : \033[0m

Enjoy your colored scripts ! 

m@

No comments:

Post a Comment