I wrote this script that I use as a login banner. My original script, much like what you see here, was only text color. I've re-tooled the script to add bold text and background color. Since doing that, I can't get it to work. Something is wrong with my syntax in that the script concatenates everything after the $BOLD to the actual output text. I suspect it's something to do with the semicolons but I've tried it 50 different ways without success. What am I missing? I know this should work because I've tested it in the terminal with the following:
#Example of multiple formats in one line
echo -e "\e[1;41;36mHello\e[0m"
The script:
#!/bin/bash
#constants
BOLD="\e[1m";
ENDCOLOR="\e[0m";
#font color selection
Black="30";
DarkGray="30";
Red="31";
LightRed="31";
Green="32";
LightGreen="32";
BrownOrange="33";
Yellow="33";
Blue="34";
LightBlue="34";
Purple="35";
LightPurple="35";
Cyan="36";
LightCyan="36";
LightGray="37";
White="37";
#bg color selection
bgDefault="49";
bgBlack="40";
bgRed="41";
bgGreen="42";
bgYellow="43";
bgBlue="44";
bgMagenta="45";
bgCyan="46";
bgLightGray="47";
bgDarkGray="100";
bgLightRed="101";
bgLightGreen="102";
bgLightYellow="103";
bgLightBlue="104";
bgLightMagenta="105";
bgLightCyan="106";
bgWhite="107";
# prints colored text
prnt () {
STR=$BOLD";"$3";"$2"m"$1$ENDCOLOR;
echo -e "$STR";
}
# prnt text textcolor bgcolor
prnt "Current Date: $(date)" $Red $bgWhite;
prnt "User Info: $(who)" $White $bgBlack;
prnt "Server Uptime: $(uptime)" $Blue $bgWhite;