web analytics

Unix: print in color

This simple procedure takes 3 arguments as the parameters:

Text Foreground color Background color

It prints the text to the terminal in selected colors.

function print_color {  local text=$1  local fg=$2  local bg=$3  case "$fg" in  red) fg="31m" ;;  green) fg="32m" ;;  yellow) fg="33m" ;;  blue) fg="34m" ;;  white) fg="37m" ;;  black) fg="30m" ;;  *) […]