Easy bash color output
To get colorized output in a bash script, you can either directly use ANSI escape codes or use tput. This is a simple color echo (cecho) function:
cecho () {
local _color=$1; shift
echo -e "$(tput setaf $_color)$@$(tput sgr0)"
}
# you can also define some variables
black=0; red=1; green=2; yellow=3; blue=4; pink=5; cyan=6; white=7;
# usage
cecho $green "success!"
# err wrapping function
err () {
cecho 1 "$@" >&2;
}
Written by Nick Jacob
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#