I have tried several approaches to building a single string for printf to display but always end up not displaying the red spaces and blank spaces following the escape sequences and printing the escape sequences instead. Here is my code:
Code:
str1="SCORE: ["
str2=$"\033[31m"
str3=`echo " " | cut -c $k`
str4=$"\033[0m"
sp=$(( 10 - $k ))
str5=`echo " " | cut -c $sp`
str6="]"
str="${str1}${str2}${str3}${str4}${str5}${str6}"
# str=$str1+$str2+$str3+$str4+$str5+$str6 didn't work either
printf "%s" "$str"
How does one use escape sequences in printf above?
BTW I also tried without the "$" in front of the escape code in str2 & 4.