Per colorare una string nella shell possiamo usare questo template:
\033[CODE1;CODE2;CODE3mTESTO\033[0m
CODE1 possono essere una serie di valori che alterano lo stile del testo, di seguito una tabella:
0Normal Characters1Bold Characters4Underlined Characters5Blinking Characters7Reverse video Characters
CODE2 invece rappresenta il colore, di seguito una tabella:
30Black31Red32Green33Yellow34Blue35Magenta36Cyan37White
CODE3 rappresenta il colore di sfondo del testo, di seguito una tabella:
40Black41Red42Green43Yellow44Blue45Magenta46Cyan47White
Per resettare il testo allo stile di default usare il carattere \033[0m.
Alcuni esempi:
echo -e "\033[31mQUESTO TESTO SARA STAMPATO IN ROSSO\033[0m"
echo -e "\033[1;36mQUESTO TESTO SARA STAMPATO IN GROSSETTO E COLOR CIANO\033[0m"
echo -e "\033[1;35;47mQUESTO TESTO SARA STAMPATO IN GROSSETTO E COLOR MAGENTA SU SFONDO BIANCO\033[0m"