Last Updated: February 25, 2016
·
1.429K
· nickjacob

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;
}