Skip to content

Instantly share code, notes, and snippets.

@AlexLamson
Created June 25, 2016 23:50
Show Gist options
  • Save AlexLamson/4ee3fe16e1614ff4e6f9c6a4e508f4fb to your computer and use it in GitHub Desktop.
Save AlexLamson/4ee3fe16e1614ff4e6f9c6a4e508f4fb to your computer and use it in GitHub Desktop.
Bash script that colors some given input text using ANSI escape codes
#color.sh
#Usage:
# ./color.sh somecolor some text to be colored
#ex. ./color.sh lightblue hello world
color='\033[0m'
nocolor="\033[0m"
case "$1" in
black) color="\033[0;30m";;
darkgray) color="\033[1;30m";;
blue) color="\033[0;34m";;
lightblue) color="\033[1;34m";;
green) color="\033[0;32m";;
lightgreen) color="\033[1;32m";;
cyan) color="\033[0;36m";;
lightcyan) color="\033[1;36m";;
red) color="\033[0;31m";;
lightred) color="\033[1;31m";;
purple) color="\033[0;35m";;
lightpurple) color="\033[1;35m";;
orange) color="\033[0;33m";;
yellow) color="\033[1;33m";;
lightgray) color="\033[0;37m";;
white) color="\033[1;37m";;
nocolor) color="$nocolor";;
esac
echo -e "${color}$2${nocolor}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment