Implementation varies between platforms, see below.
cecho "Hello world" yellow
This script assumes your terminal has a black background, to use with white terminals replace ;40m
with ;47m
for each color. (There are more colors, try them out!)
cecho() {
black='\033[30;40m'
red='\033[31;40m'
green='\033[32;40m'
yellow='\033[33;40m'
blue='\033[34;40m'
magenta='\033[35;40m'
cyan='\033[36;40m'
white='\033[37;40m'
echo -e ${!2}$1
tput sgr0
return
}
cecho() {
black='\E[30;40m'
red='\E[31;40m'
green='\E[32;40m'
yellow='\E[33;40m'
blue='\E[34;40m'
magenta='\E[35;40m'
cyan='\E[36;40m'
white='\E[37;40m'
echo -e ${!2}$1
tput sgr0
return
}