Last active
September 6, 2017 14:29
-
-
Save obstschale/1e1789730a399131d490e30e421e229b to your computer and use it in GitHub Desktop.
Bash function for colored output. (source: https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux#answer-28709668)
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
cecho() { | |
local code="\033[" | |
case "$1" in | |
black | bk) color="${code}0;30m";; | |
red | r) color="${code}1;31m";; | |
green | g) color="${code}1;32m";; | |
yellow | y) color="${code}1;33m";; | |
blue | b) color="${code}1;34m";; | |
purple | p) color="${code}1;35m";; | |
cyan | c) color="${code}1;36m";; | |
gray | gr) color="${code}0;37m";; | |
*) local text="$1" | |
esac | |
[ -z "$text" ] && local text="$color$2${code}0m" | |
echo -e "$text" # The -e flag is needed on macOS. Other systems might not need it. | |
} | |
cecho "Normal" | |
cecho y "Yellow!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment