From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3947 invoked from network); 5 Oct 1998 09:30:18 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 5 Oct 1998 09:30:18 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id FAA14759; Mon, 5 Oct 1998 05:18:02 -0400 (EDT) Resent-Date: Mon, 5 Oct 1998 05:18:02 -0400 (EDT) From: "Bart Schaefer" Message-Id: <981005022013.ZM1469@candle.brasslantern.com> Date: Mon, 5 Oct 1998 02:20:13 -0700 In-Reply-To: <9810050747.AA12241@ibmth.df.unipi.it> Comments: In reply to Peter Stephenson "Re: Bug? in 'integer' behaviour" (Oct 5, 9:47am) References: <9810050747.AA12241@ibmth.df.unipi.it> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Peter Stephenson , Phil Pennock , zsh-workers@math.gatech.edu Subject: Re: Bug? in 'integer' behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"gzX421.0.Vc3.Ax86s"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4408 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Oct 5, 9:47am, Peter Stephenson wrote: } Subject: Re: Bug? in 'integer' behaviour } } Phil Pennock wrote: } > # get a random line from a file } > integer z=$(wc -l <"$1") } > sed -n $[RANDOM%z+1]p "$1" } > } > This produces a divide by zero error, as 'z' is always zero. Removing } > the 'integer' keyword solves this, as does wrapping the RHS of the } > assignment in $[...]. } } I think it's the trailing characters after the number which are causing } the problem. From wc you get something like } 128 .zshrc No, that can't be right. Note that input is being redirected to wc, so it doesn't produce the trailing file name. See: zagzig% set -vx zagzig% . ./randline multicomp . ./randline multicomp + . ./randline multicomp # get a random line from a file integer z=$(wc -l <$1) + wc -l + integer z= 73 sed -n $[RANDOM%z+1]p $1 ./randline: division by zero [3] zagzig% echo $z echo $z + echo 0 0 It's possible that some wc implementations don't emit the leading space when given only -l, but GNU wc does. It's also possible that some past version of zsh ignored the leading space when computing the integer value of the string assigned to the variable (though both 3.0.5 and 3.1.4 give zero); that function has been around for a VERY long time, and I don't think any maintainer has ever bothered regression-testing those samples when making a new release. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com