home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / std_unix / volume.31 / text0039.txt < prev    next >
Encoding:
Text File  |  1993-07-15  |  1.5 KB  |  36 lines

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