zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Peter Stephenson <pws@ibmth.df.unipi.it>,
	Phil Pennock <phil@athenaeum.demon.co.uk>,
	zsh-workers@math.gatech.edu
Subject: Re: Bug? in 'integer' behaviour
Date: Mon, 5 Oct 1998 02:20:13 -0700	[thread overview]
Message-ID: <981005022013.ZM1469@candle.brasslantern.com> (raw)
In-Reply-To: <9810050747.AA12241@ibmth.df.unipi.it>

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


  reply	other threads:[~1998-10-05  9:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-04 23:18 Phil Pennock
1998-10-05  7:47 ` Peter Stephenson
1998-10-05  9:20   ` Bart Schaefer [this message]
1998-10-05  9:33     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=981005022013.ZM1469@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=phil@athenaeum.demon.co.uk \
    --cc=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).