From owner-freebsd-bugs Sun May 7 00:00:43 1995 Return-Path: bugs-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id AAA08550 for bugs-outgoing; Sun, 7 May 1995 00:00:43 -0700 Received: from irz301.inf.tu-dresden.de (irz301.inf.tu-dresden.de [141.76.1.11]) by freefall.cdrom.com (8.6.10/8.6.6) with SMTP id AAA08524 for ; Sun, 7 May 1995 00:00:32 -0700 Received: from sax.sax.de by irz301.inf.tu-dresden.de with SMTP (5.67b+/DEC-Ultrix/4.3) id AA12986; Sun, 7 May 1995 09:00:28 +0200 Received: by sax.sax.de (8.6.12/8.6.12-s1) with UUCP id JAA26300 for freebsd-bugs@FreeBSD.org; Sun, 7 May 1995 09:00:28 +0200 Received: (from j@localhost) by uriah.heep.sax.de (8.6.11/8.6.9) id IAA07462 for freebsd-bugs@FreeBSD.org; Sun, 7 May 1995 08:55:53 +0200 From: J Wunsch Message-Id: <199505070655.IAA07462@uriah.heep.sax.de> Subject: Re: bin/386: *s field width specification doesn't seem to work for printf To: freebsd-bugs@FreeBSD.org Date: Sun, 7 May 1995 08:55:51 +0200 (MET DST) Reply-To: freebsd-bugs@FreeBSD.org In-Reply-To: from "j" at May 7, 95 05:24:08 am Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) X-Phone: +49-351-2012 669 X-Mailer: ELM [version 2.4 PL23] Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Content-Length: 1148 Sender: bugs-owner@FreeBSD.org Precedence: bulk As j wrote (that's me, ain't it? :): > "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. I think i've fixed it now. printf did a very lax syntax checking. Digits and the asterisk have been treated equally in a fieldwidth/ precision string, resulting in "8*" being believed to be valid. The paragraph o If the leading character is a single or double quote, or not a digit, plus, or minus sign, the value is the ASCII code of the next character. however explains why "foobarblatt" is considered to be the valid number 102 (the ASCII value of "f"). It's weird, but intention. Jordan: for your intention (to _limit_ the output width, if i understood you right), you need to specify the precision, not the field width: printf "%.8s" foobarblatt or printf "%.*s" ${FIELD_LENGTH} foobarblatt -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ Never trust an operating system you don't have sources for. ;-)