Bash: use colored text in script

I often use these handy helperfunction to write colored text in my scripts.

# Bash text-colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

function echoRed() {
  TEXT=$1
  printf "${RED}${TEXT}${NC}\n"
}

function echoGreen() {
  TEXT=$1
  printf "${GREEN}${TEXT}${NC}\n"
}

echoGreen "This text is green"
echoRed "This text is red"
echo "This is regular text"

Click Here to Leave a Comment Below

Leave a Reply: