There is printf %q, a bashism I think
Sample usage to escape var called v v="$(printf '%q' "$v")"
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...