From owner-freebsd-bugs Sat May 6 21:49:40 1995 Return-Path: bugs-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id VAA05059 for bugs-outgoing; Sat, 6 May 1995 21:49:40 -0700 Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.34]) by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id VAA05047 for ; Sat, 6 May 1995 21:49:28 -0700 Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.9/8.6.9) id OAA02207 for freebsd-bugs@FreeBSD.org; Sun, 7 May 1995 14:45:47 +1000 Date: Sun, 7 May 1995 14:45:47 +1000 From: Bruce Evans Message-Id: <199505070445.OAA02207@godzilla.zeta.org.au> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/386: *s field width specification doesn't seem to work for printf Sender: bugs-owner@FreeBSD.org Precedence: bulk >> > Try this: printf "%8*s" foobarblatt >> You are missing the required int arg for the * and foobarblatt is being >> used for this int. foobarblatt is probably some rather very large int Not quite. It's a nonsense format. The behaviour is undefined. printf(1) ends up calling printf(3) with printf("%8*s", "foobarblatt"). >"foobarblatt" ain't a valid int. printf(1) misses an argument in that >case. It expected two args (for the * and for the s) and got only >one. The least one could expect is it loudly complains about this. printf(1) doesn't seem to do any more error checking than printf(3). >Furthermore, if you omit the asterisk, you'll be surprised that you >can still see a very nice "foobarblatt" instead of the expected >"foobarbl". You can also replace the command by > printf "%*s" 8 foobarblatt >to the same avail. No, the 8 is the (minimum) field width. printf "%.*s" 8 foobarblatt specifies the precision as 8 to truncate the string. Bruce