Skip to content

Instantly share code, notes, and snippets.

@mavieth
Created February 26, 2016 19:36
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mavieth/49674d35f00e39c81dcb to your computer and use it in GitHub Desktop.
Save mavieth/49674d35f00e39c81dcb to your computer and use it in GitHub Desktop.
Bash script color output
#!/bin/bash
DARKGRAY='\033[1;30m'
RED='\033[0;31m'
LIGHTRED='\033[1;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
LIGHTPURPLE='\033[1;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
SET='\033[0m'
echo "I ${DARKGRAY}love${SET} github."
echo "I ${RED}love${SET} github."
echo "I ${LIGHTRED}love${SET} github."
echo "I ${GREEN}love${SET} github."
echo "I ${YELLOW}love${SET} github."
echo "I ${BLUE}love${SET} github."
echo "I ${PURPLE}love${SET} github."
echo "I ${LIGHTPURPLE}love${SET} github."
echo "I ${CYAN}love${SET} github."
echo "I ${WHITE}love${SET} github."
@asmattic
Copy link

asmattic commented Nov 8, 2018

In order for the backslash escapes to work with echo, you need to add the -e option after echo and before the string to be echoed.

For example:

echo -e "I ${RED}love${SET} github."

From the echo man page: -e enable interpretation of backslash escapes

Without it, the output is I \033[0;31mlove\033[0m github. for the same line in a normal bash shell. I'm sure this was figured out a long time ago seeing the age of this Gist but I figured I'd put it here for anyone coming across this in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment