[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf treats arguments of "%c" not as expected
From: |
Jonathan Nieder |
Subject: |
Re: printf treats arguments of "%c" not as expected |
Date: |
Wed, 22 Jun 2011 16:19:48 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi,
Yunfeng Wang wrote:
> $ printf %c 65 66 67
> 666
>
> The expected output is ABC, i.e. characters with ASCII code of 65 66 67
I believe the current behavior is correct. POSIX (XCU.4.printf) sayeth[*]:
11. The argument to the 'c' conversion specifier can be a string
containing zero or more bytes. If it contains one or more
bytes, the first byte shall be written and any additional bytes
shall be ignored. If the argument is an empty string, it is
unspecified whether nothing is written or a null byte is written.
I would suggest using something like
perl -e 'print(chr(65), chr(66), chr(67), "\n");'
or
for i in 65 66 67
do
eval printf \'\\$(printf %03o "$i")\'
done
printf '\n'
for your application.
Back to the bug: I don't see any explanation of "printf %c" when I run
"man bash". Perhaps your manual is different from mine, but if you,
perhaps it would be possible to suggest a few words to explain this
for future readers.
Thanks and regards,
Jonathan
[*] http://unix.org/2008edition/