From owner-freebsd-standards@FreeBSD.ORG Fri May 30 19:30:01 2008 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 109931065675 for ; Fri, 30 May 2008 19:30:01 +0000 (UTC) (envelope-from stefan@fafoe.narf.at) Received: from viefep32-int.chello.at (viefep32-int.chello.at [62.179.121.50]) by mx1.freebsd.org (Postfix) with ESMTP id 818378FC21 for ; Fri, 30 May 2008 19:30:00 +0000 (UTC) (envelope-from stefan@fafoe.narf.at) Received: from lizard.fafoe.narf.at ([213.47.85.26]) by viefep32-int.chello.at (InterMail vM.7.08.02.02 201-2186-121-104-20070414) with ESMTP id <20080530192958.FTWP25835.viefep32-int.chello.at@lizard.fafoe.narf.at>; Fri, 30 May 2008 21:29:58 +0200 Received: by lizard.fafoe.narf.at (Postfix, from userid 1001) id 94A78BAD1; Fri, 30 May 2008 21:29:29 +0200 (CEST) Date: Fri, 30 May 2008 21:29:29 +0200 From: Stefan Farfeleder To: Kostik Belousov Message-ID: <20080530192929.GB1056@lizard.fafoe.narf.at> Mail-Followup-To: Kostik Belousov , freebsd-standards@freebsd.org References: <20080530172711.GA1056@lizard.fafoe.narf.at> <20080530181242.GC21317@deviant.kiev.zoral.com.ua> <20080530181529.GD21317@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080530181529.GD21317@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.5.17 (2007-11-01) Cc: freebsd-standards@freebsd.org Subject: Re: $LINENO within functions 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, 30 May 2008 19:30:01 -0000 On Fri, May 30, 2008 at 09:15:29PM +0300, Kostik Belousov wrote: > On Fri, May 30, 2008 at 09:12:42PM +0300, Kostik Belousov wrote: > > On Fri, May 30, 2008 at 07:27:12PM +0200, Stefan Farfeleder wrote: > > > Hi, > > > > > > SUSv3 says the following about $LINENO: > > > > > > "Set by the shell to a decimal number representing the current > > > sequential line number (numbered starting with 1) within a script or > > > function before it executes each command. If the user unsets or resets > > > LINENO , the variable may lose its special meaning for the life of the > > > shell. If the shell is not currently executing a script or function, the > > > value of LINENO is unspecified. This volume of IEEE Std 1003.1-2001 > > > specifies the effects of the variable only for systems supporting the > > > User Portability Utilities option." > > > > > > My initial interpretation of "or function" was that it means $LINENO > > > within a function should be relative to the function's beginning line. > > > Now I'm not so sure anymore. Bash release 2.05b changed the expansion > > > of $LINENO within functions to absolute numbering, stating this is > > > required by POSIX. But then I wonder about the meaning of "or > > > function". Does it mean functions in interactive scripts? Because for > > > functions in shell scripts the mentioning of both "script" and > > > "function" seems redundant. > > > > I do not know whether you need this data, but ksh93 and pdksh exhibit > > the same behaviour as bash. For the rev. 1.1 of lineno.0, I got > > > > 2 > > 3 > > 6 > > 7 > > 12 > > 13 > > foo > > foo > > 2 > > > > On the other hand, zsh produces > > > > 2 > > 3 > > 1 > > 2 > > 12 > > 13 > > foo > > foo > > 2 > > Oh, and /usr/xpg4/bin/sh on the fully patches Solaris 10 output is identical > with the zsh one. Yes, the current implementation has a +1 offset compared to zsh. The reason is that $LINENO can occur on the same line as the function name itself (ie. zsh prints 0 for 'f() { echo $LINENO }' which contradicts the specification).