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?
You don't. This should work fine:
git config --global alias.foo '!a="C:\New folder"; printf "%s\n" "$(basename "$a")"'