[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash/printf question
From: |
Pablo Saratxaga |
Subject: |
Re: bash/printf question |
Date: |
Thu, 28 Dec 2000 05:25:08 +0100 |
Kaixo!
Li Sat, 23 Dec 00 16:00:01 +0100,
James Vahn <address@hidden> scrîjheut:
JV> ~$ A=66; B=$[ A + 1 ]; /usr/bin/printf "%c\n" $B
JV> I'm looking for a "C" to be printed. It's showing a "6" instead.
The problem is not with printf (the shell command is just a wrapper calling
the printf() from libc) but with the shell; how do you pass a *number*
and not a char as parameter ?
when you do 'printf "%c\n" 6' you are not passing the number 6, but instead
you are passing '6' (with quotes), that is the number 0x36.
JV> This works:
JV> ~$ A=66; export B=$[ A + 1 ]; perl -e 'printf("%c\n", $ENV{B})'
Because perl converts strings that can be parsed as numbers to numbers;
the shell doesn't.
When you type 66 in the shell you are not typing 66 but two bytes of value
0x36. When you type 66 in perl you are typing a number 66 (0x42)
How does it works for printf "%x" (and %d etc) then ? Well, the shell wrapper
seems to call a parser for them (as the argument is known to be a number).
It doesn't for %c apparently. Is that a bug ? It seems so to me.
chanae:~$ /usr/bin/printf --help | grep bug
Report bugs to <address@hidden>.
You know where to report the bug now.
(I Cc: them)
--
Pablo Saratxaga PGP key 0x8F0E4975
Zerbait gaizki gertatzen ahal balitz, zerbait gertatuko da. -- Murphy
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: bash/printf question,
Pablo Saratxaga <=