Source: https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
Anything to add? Let's talk @kgoutsos. Share this page on Twitter, Facebook, LinkedIn or use the permalink.Changing output colour in Bash
There is a large number of ANSI escape codes to make your terminal do ‘unusual’ things. Some basic colours for example are the following:
Colour | Code | Colour | Code | |
---|---|---|---|---|
Black | 0;30 | Dark Gray | 1;30 | |
Red | 0;31 | Light Red | 1;31 | |
Green | 0;32 | Light Green | 1;32 | |
Brown/Orange | 0;33 | Yellow | 1;33 | |
Blue | 0;34 | Light Blue | 1;34 | |
Purple | 0;35 | Light Purple | 1;35 | |
Cyan | 0;36 | Light Cyan | 1;36 | |
Light Gray | 0;37 | White | 1;37 |
Usage example:
RED='\033[0;31m'
NC='\033[0m' # No Colour
printf "This is an ${RED}ERROR${NC}\n"
which prints the word ‘ERROR’ in red and the rest of the phrase in the default colour.
If you are using the echo
command, remember to use the -e
flag to make echo
obey the backslash escape sequences: echo -e "${RED}This is an ERROR${NC}"
Links
- Full list of ANSI codes with more colours and examples.
- echo command manual page