From owner-freebsd-standards@FreeBSD.ORG Fri Jul 7 22:24:14 2006 Return-Path: X-Original-To: freebsd-standards@freebsd.org Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5490416A4DF for ; Fri, 7 Jul 2006 22:24:14 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id 87EFC43D45 for ; Fri, 7 Jul 2006 22:24:12 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.pc (host5.bedc.ondsl.gr [62.103.39.229]) (authenticated bits=128) by igloo.linux.gr (8.13.7/8.13.7/Debian-1) with ESMTP id k67MNnwu016586 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 8 Jul 2006 01:23:50 +0300 Received: from gothmog.pc (gothmog [127.0.0.1]) by gothmog.pc (8.13.7/8.13.7) with ESMTP id k67MNhxQ010807; Sat, 8 Jul 2006 01:23:44 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.pc (8.13.7/8.13.7/Submit) id k67MNhfd010806; Sat, 8 Jul 2006 01:23:43 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Sat, 8 Jul 2006 01:23:43 +0300 From: Giorgos Keramidas To: Jan Grant Message-ID: <20060707222343.GA10756@gothmog.pc> References: <20060707201402.T14116@tribble.ilrt.bris.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060707201402.T14116@tribble.ilrt.bris.ac.uk> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-3.641, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.76, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-standards@freebsd.org Subject: Re: stdio/sh behaviour guaranteed? X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jul 2006 22:24:14 -0000 On 2006-07-07 20:23, Jan Grant wrote: > Consider the following snippet. > > [[[ > #!/bin/sh > > echo one > t > while read line > do > echo $line > case $line in > one) echo two >> t > ;; > two) echo three >> t > ;; > esac > done ]]] > > This produces three lines of output on FreeBSD: which is what > I'd intuitively expect and it's certainly useful behaviour. > > I'm just trying to determine if that behaviour is one that I > can rely on - in other words, I guess, if stdio performs a > "short read" that fails to fill a buffer, and the underlying > file is then extended outside the process, will another attempt > to read from the FILE* (or a test of feof, say) honour the new, > longer file contents? I think that /bin/sh is not absolutely required to use stdio.h for input (which could pre-read some text and cause the above to fail). Having said that, I think it makes sense to assume that input is line-buffered, otherwise stuff like this could fail: cmd | while read line ; do echo "$line" ; done > And in particular, is the idiom above blessed by appropriate > posix standards? Not sure, but the behavior seems to be the same in Solaris too, with a variety of shells: | kobe % cat /etc/release | Solaris 10 1/06 s10x_u1wos_19a X86 | Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. | Use is subject to license terms. | Assembled 07 December 2005 | kobe % pwd | /tmp/t | kobe % cat -n foo.sh | 1 #!/bin/sh | 2 | 3 echo one > t | 4 while read line | 5 do | 6 echo $line | 7 case $line in | 8 one) echo two >> t | 9 ;; | 10 two) echo three >> t | 11 ;; | 12 esac | 13 done