Sam's Blog

Shell-quoting future me, printf -v "%q" is what you're looking for

Date: Friday, 15 June 2012, 12:59.

Categories: bash, shell-scripting, note-to-future-me.

Note to future me: Are you trying to remember how to shell-quote/escape the contents of a variable to avoid going utterly insane from the nested double-quotes and backslashing?

printf -v escaped_var "%q" "$var" is the command that you can never remember, and never find the documentation for until you've wasted a morning of your life.

Don't forget it next time. Or at least, remember that you wrote this note, kthxbai.

Browse Sam's Blog Subscribe to Sam's Blog

By day of June: 07, 08, 15.

By month of 2012: April, May, June, July, December.

By year: 2010, 2011, 2012, 2013.

Or by: category or series.


blog comments powered by Disqus
© 2009-2013 Sam Graham, unless otherwise noted. All rights reserved.