I'm having weird issues with Bash displaying colors from a function I wrote. If it was consistent, that'd be one thing, but I recently built 10 identical instances of RedHat (7.4), and 1 of the 10 is having the problem - the other 9 are working fine.
So I have a function that enables me to print color status messages (simplified for brevity):
printStatus () {
local COLOUR_BLUE="\e[0;34m"
local COLOUR_GREEN="\e[0;32m"
local COLOUR_NORMAL="\e[0;0m"
local COLOUR_RED="\e[0;31m"
local COLOUR_YELLOW="\e[0;33m"
case ${1} in
"EMPTY")
printf "[ ]"
;;
"FAIL")
printf "[ ${COLOUR_RED}FAIL${COLOUR_NORMAL} ]"
;;
"INFO")
printf "[ ${COLOUR_BLUE}INFO${COLOUR_NORMAL} ]"
;;
"NOTE")
printf "[ NOTE ]"
;;
"OK")
printf "[ ${COLOUR_GREEN}OK${COLOUR_NORMAL} ]"
;;
"WARN")
printf "[ ${COLOUR_YELLOW}WARN${COLOUR_NORMAL} ]"
;;
*)
printf "${1}"
;;
esac
}
So when I call it like this in a script:
printStatus FAIL
it always works as expected (FAIL being in red):
[ FAIL ]
If I call it like this:
printf "%s : This is not going to work\n" $( printStatus FAIL )
it works on 90%+ of my builds. When it doesn't work, all I get is (no color):
1
Which screams (to me) that it's a return code somehow, but why? If it was like this 100% of the time it'd make some sense, but it doesn't. And the really weird part is that it's only for red - if I changed the FAIL condition above to use any other color, it works fine with the new color. I can't for the life of me see what is different for those builds that aren't working. Using "set -x" in my script shows everything to be as I expect.
If it means anything, my version of Bash is: GNU bash, version 4.2.46(2)-release.
Thanks in advance.