home *** CD-ROM | disk | FTP | other *** search
- Submitted-by: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
-
- In article <1r77kaINN83e@ftp.UU.NET>, djm@eng.umd.edu (David J. MacKenzie) writes:
- > Several people have complained that the GNU printf program (part of
- > the GNU shell utilities) handles %c in a less than useful way: it
- > treats the argument as a string and prints the first character.
- > That is how I had interpreted POSIX.2; in particular, this paragraph
- > from the printf section of draft 11.2:
-
- Just speaking as a user: I have my own printf(1L) and have had since before
- Chris Torek's came out. Mine was intended to be as much like C's as it
- could be, and in particular it was important that
- printf %c 10
- should write a linefeed. In the current version of my printf(),
- any time that C's printf would accept an integer, mine accepts
- any expression that M4's eval() would accept, so
- printf "%c" "'\n' == 10 ? 10 : 13"
- does something useful. It was ever so simple to make this work, and has
- not significantly increased the size of the program. (That code is free...)
-
- > I have heard that Chris Torek's BSD printf program does the same thing
- > with %c, but I haven't verified that myself.
-
- I just tried it, and yes, it _does_ do that rather useless thing.
- If we wanted that, we could use
- printf %.1s 3
- To quote the on-line manual page:
- Printf duplicates (as far as possible) the standard C
- library routine of the same name, at the shell command level.
- If it botches %c like this, then it _doesn't_ duplicate printf(3s) at
- command level.
-
-
- Volume-Number: Volume 31, Number 41
-
-