Last active
August 29, 2015 14:09
-
-
Save btcrooks/89c8a6003d332c792e39 to your computer and use it in GitHub Desktop.
Color Commands for Shell Scripting (Bash)
This file contains 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/sh | |
# Here are a set of color commands for | |
# your shell scripts. | |
#----------------Colors------------------ | |
#Black 0;30 Dark Gray 1;30 | |
#Blue 0;34 Light Blue 1;34 | |
#Green 0;32 Light Green 1;32 | |
#Cyan 0;36 Light Cyan 1;36 | |
#Red 0;31 Light Red 1;31 | |
#Purple 0;35 Light Purple 1;35 | |
#Brown/Orange 0;33 Yellow 1;33 | |
#Light Gray 0;37 White 1;37 | |
#No Color 0 | |
#---------------------------------------- | |
# Assgin a color to a variable | |
# -e tells terminal to enable color coding | |
#------------Usage----------------------- | |
# ALL OS's | |
red='\033[0;31m' | |
NC='\033[0m' # Always close with No Color | |
echo -e "${red}Hello, World${NC}" | |
# Optional os specific implementations | |
# Linux only | |
red='\e[0;31m' | |
NC='\e[0m' #Always close with No Color | |
echo -e "${red}Hello, World${NC}" | |
# Mac OS X only | |
red='\x1b[0;31m' | |
NC='\x1b[0m' #Always close with No Color | |
echo -e "${red}Hello, World${NC}" | |
#---------------------------------------- | |
# Note | |
# Always close with " \x1b[0m " which resets the | |
# color back to no color. If you don't, the users | |
# terminal will stay with the last color assigned. | |
# The following would turn everything red. | |
# Including the following command line prompt -- | |
red='\033[0;31m' | |
echo -e "${red}OMG Everything is red..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment