3 ms·
There is printf %q, a bashism I think Sample usage to escape var called v v="$(printf '%q' "$v")"
by phh 5y ago
There is printf %q, a bashism I think
Sample usage to escape var called v
v="$(printf '%q' "$v")"
- formerly_proven 5y agoThanks!
- unqueued 5y agoThis is called ANSI-C quoting[1], and I am surprised it is not more popular, because I think it provides a good compromise with readability and power. 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_002dC-Quoting https://www.gnu.org/software/bash/manual/bash.html#ANSI_002d... [2]: https://github.com/unqueued/storetouch https://github.com/unqueued/storetouch