Adding color to your shell is going to make your scripts more usable and friendly.
So we can proudly echo “Hello world” from our scripts now and in lesson 8 we could see that we can send different echo statements based on interrupts sent to the script. Now we will see how we can make the scripts a little more user-friendly by using colour in our output.
echo -e "\e[0;31m Would echo in dark red"
So we can read into this that \e[0;31m is the code for dark red, to reset the color to normal we would use \e[0m for normal color. That said the line would then read :
echo -e “\e[0;31m Would echo in dark red\e[0m”
If the first number is 0 we use dark colours if it is 1 it is a light color; so for light red :
echo -e “\e[1;31m Would echo in light red\e[0m”
Black 0;30 Dark Gray 1;30
Dark Red 0;31 Light Red 1;31
Dark Green 0;32 Light Green 1;32
Dark Yellow 0;33 Light Yellow 1;33
Dark Blue 0;34 Light Blue 1;34
Dark Purple 0;35 Light Purple 1;35
Dark Cyan 0;36 Light Cyan 1;36
Light Gray 0;37 White 1;37
If you want to work with the background colour then, the numbers are 40-47 in place of 30-37. Making adding color useful in the foreground and background. But take care on readability.