Am 11.01.2013 19:38, schrieb Dan Douglas:
> $ set --; printf %q\\n "$@"
> ''
>
> printf should perhaps only output '' when there is actually a corresponding
> empty argument, else eval "$(printf %q ...)" and similar may give different
> results than expected. Other shells don't output '', even mksh's ${var@Q}
> expansion. Zsh's ${(q)var} does.
that is not a bug in printf %q
it what you expect to happen with "${@}"
should that be 0 arguments if $# is 0.
I however find the behavior irritating, but correct from the description.
to do what you are suggesting you would need a special case handler for this
"${@}" as oposed to "jjjj${@}jjjjj" or any other variation.
what I tend to do as a workaround is
printf() {
if [ $# -eq 2 -a -z "${2}" ];then
builtin printf "${1}"
else
builtin printf "${@}"
fi
}
or not as good but ok in most cases something like
printf "%q" ${1:+"${@}"}