Created
February 26, 2016 19:36
-
-
Save mavieth/49674d35f00e39c81dcb to your computer and use it in GitHub Desktop.
Bash script color output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order for the backslash escapes to work with
echo
, you need to add the-e
option afterecho
and before the string to be echoed.For example:
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.