Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

bash – How can I escape double quotes inside double quotes in printf?

I want to provide an argument with spaces to a function in the second argument of printf inside a git alias.

git config --global alias.foo '!a="C:\New folder"; printf "%s\n" "$(basename $a)"'
git config --global alias.foo '!a="C:\New folder"; printf "%s\n" "$(basename \"$a\")"'
git config --global alias.foo '!a="C:\New folder"; printf "%s\n" "$(basename "\""$a"\"")"'

git config --global alias.foo '!a="C:\New folder"; b=$(basename "$a"); printf "%s\n" "$b"'

The first three yield New. The last one avoids the issue and yields New folder as intended. How can I write the alias without using an additional variable?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Don’t escape the double-quotes around $a.

git config --global alias.foo '!a="C:\New folder"; printf "%s\n" "$(basename "$a")"'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading