Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: printf for converting numbers to letters, bug?



> Zsh is (as of 4.2.0) behaving such that, given x='101',
> 
> 	printf "%c" $x
> and
> 	print -r $x[1]
> 
> produce the same output.  That behavior is nearly useless.  (It is how
> /usr/bin/printf on Linux works, though, so I guess it can be interpreted
> as a compatibility issue.)

Solaris too.

> If %b interprets the string \0101 as an octal number and prints the
> corresponding character, why shouldn't %c interpret the string 101 as a
> decimal number and print the corresponding character?

Compatibility.  I think an option to do that would be okay, though
perhaps a bit confusing.  I think it would be nice if bin_printf could
peek back in time to see if $x had PM_INTEGER set before it got
expanded, but that seems like more trouble than it's worth.

>   http://www.opengroup.org/onlinepubs/007904975/utilities/printf.html
> 
> I notice that although it mentions %b, there's NO definition of %b on any
> of the pages it cross-references:
> 
>   http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap05.html
>   http://www.opengroup.org/onlinepubs/007904975/functions/printf.html
> 
> Where is %b defined?

In #7 of EXTENDED DESCRIPTION of the first URL you cited.



Messages sorted by: Reverse Date, Date, Thread, Author