bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printf %q represents null argument as empty string.


From: Dan Douglas
Subject: Re: printf %q represents null argument as empty string.
Date: Fri, 11 Jan 2013 15:05:53 -0600
User-agent: KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; )

On Friday, January 11, 2013 09:39:00 PM John Kearney wrote:
> 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 
> > address@hidden 
> > expansion. Zsh's ${(q)var} does.
> 
> that is not a bug in printf %q
> 
> it what you expect to happen with "address@hidden" 
> 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
> "address@hidden" as oposed to "address@hidden" 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 "address@hidden"
>     fi
> }
> 
> 
> or not as good but ok in most cases something like
> 
> printf "%q" ${1:+"address@hidden"}
> 
> 

I don't understand what you mean. The issue I'm speaking of is that printf %q 
produces a quoted empty string both when given no args and when given one 
empty arg. A quoted "$@" with no positional parameters present expands to zero 
words (and correspondingly for "address@hidden"). Why do you think 
"address@hidden" is 
special? (Note that expansion didn't even work correctly a few patchsets ago.)

Also as pointed out, every other shell with a printf %q feature disagrees with 
Bash. Are you saying that something in the manual says that it should do 
otherwise? I'm aware you could write a wrapper, I just don't see any utility 
in the default behavior.
-- 
Dan Douglas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]