You are not logged in.

#1 2012-08-02 12:04:42

Marcus27
Member
From: Hamburgo
Registered: 2012-07-05
Posts: 11

Problem with printf

I found a line in Greg's Wiki I cannot find an explanation for:

>printf '%d' "'A" # double quotes + 1 single quote
65

>printf '%d' "'A'" # double quotes + 2 single quotes
65

>printf '%d' 'A' # just single quotes
bash: printf: A: invalid number
0

>printf '%d' '"A"'
65

>printf '%d' '"A' # single quotes + 1 double quote
65

Can somebody perhaps tell me where this behaviour is explained?

Offline

#2 2012-08-02 12:26:24

Marcus27
Member
From: Hamburgo
Registered: 2012-07-05
Posts: 11

Re: Problem with printf

Ok, accidently found out that this is printf specific. (Strangly neither in man pages nor in "info coreutils 'printf invocation'" mentioned.)

http://pubs.opengroup.org/onlinepubs/00 … rintf.html

Offline

#3 2012-08-02 12:43:29

progandy
Member
Registered: 2012-05-17
Posts: 5,279

Re: Problem with printf

It is mentioned in the textinfo page.

If the leading character of a numeric argument is `"' or `'' then
     its value is the numeric value of the immediately following
     character.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#4 2012-08-03 13:00:18

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Problem with printf

If you've got your answers, please remember to mark the thread as solved.
https://bbs.archlinux.org/viewtopic.php?id=130309

Offline

Board footer

Powered by FluxBB