how to change colors in terminal linux outputs code example

Example 1: how to change colors in terminal linux outputs

#!/bin/sh
RED_ON_GREEN='\033[31;42m'
RESET='\033[0m'
echo "${RED_ON_GREEN}Hello world${RESET}"

Example 2: how to change colors in terminal linux outputs

#!/bin/sh
RED_FG=`tput setaf 1`
GREEN_BG=`tput setab 2`
RESET=`tput sgr0`
echo "${RED_FG}${GREEN_BG}Hello world${RESET}"

Example 3: how to change colors in terminal linux outputs

#!/bin/sh
MOVE_UP=`tput cuu 1`
CLEAR_LINE=`tput el 1`
BOLD=`tput bold`
UNDERLINE=`tput smul`
RESET=`tput sgr0`
echo "This is normal text"
sleep 1
echo "${MOVE_UP}${CLEAR_LINE}${BOLD}This is bolded"
sleep 1
echo "${MOVE_UP}${CLEAR_LINE}${UNDERLINE}This is underlined${RESET}"

Tags:

Misc Example