I can change my cursor shape like this:
printf "\x1b[\x31 q" # block :)
printf "\x1b[\x35 q" # ibeam :)
But when I assign that to a variable with %s and expand using printf, it doesn't work:
CURSOR="\x1b[\x3%s q"
printf ${CURSOR} 1 # block :(
printf ${CURSOR} 5 # ibeam :(
How do I fix this?
printfsees are\x1b[\x3%s,qand1(or5). Sinceprintfreuses format strings until the arguments are exhausted, the format string is printed twice, once withqreplacing%sand once with1(or5). You should quote your variables there; otherwise it has a completely different meaning.printfdoes not support hex backslash escapes? Your code is not portable as it relies on non-POSIX features.