It always seemed very strange to me that there is no way to generate escaped representations in sh/bash, because you do need that from time to time.
Sample usage to escape var called v v="$(printf '%q' "$v")"
I used it myself when I wrote a script that generates a self executing bash script to restore mtimes for directories[2]
[1]: https://www.gnu.org/software/bash/manual/bash.html#ANSI_002d...