I had these lines:
if [[ $# -eq 0 ]]; then
printf "$fail_color Error - Function: $function, Line: $line_number \n"
printf "do_test: Third parameter missing - expected result\n"
exit 1
fi
This works fine and gives me the intended output of Error - Function: words, Line: 94
I then used ShellCheck and it recommended
printf "$fail_color Error - Function: $function, Line: $line_number \n
^––SC2059 Don't use variables in the printf format string. Use printf "..%s.." "$foo".
So I tried changing it to
printf "%s Error - Function: %s, Line: %s \n", "$fail_color", "$function", "$line_number"
but now the output shows the color code details instead of the color:
\033[31;1m, Error - Function: words,, Line: 94
,do_test: Third parameter missing - expected result
Related - is there a better way to name the strings other than multiple %s
's?
Detail - the color are defined this way:
fail_color="\033[31;1m"
pass_color="\033[32;1m"
color_end="\033[0m"