From owner-freebsd-questions@FreeBSD.ORG Thu Sep 30 20:08:01 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EAE0E16A4CE for ; Thu, 30 Sep 2004 20:08:01 +0000 (GMT) Received: from mx2.mail.ru (mx2.mail.ru [194.67.23.122]) by mx1.FreeBSD.org (Postfix) with ESMTP id A216943D46 for ; Thu, 30 Sep 2004 20:08:01 +0000 (GMT) (envelope-from infofarmer@mail.ru) Received: from [83.237.13.52] (port=4838 helo=SATPC) by mx2.mail.ru with smtp id 1CD7Dc-000P8Z-00; Fri, 01 Oct 2004 00:08:00 +0400 Message-ID: <004901c4a729$61fc7810$4611a8c0@SATPC> From: "Andrew" To: "Dan Nelson" References: <000601c4a720$99264270$4611a8c0@SATPC> <20040930194001.GD22530@dan.emsphone.com> Date: Fri, 1 Oct 2004 00:09:24 +0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Spam: Not detected cc: freebsd-questions@freebsd.org Subject: Re: 64-bit arithmetic in scripts? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Sep 2004 20:08:02 -0000 Dan Nelson wrote: > In the last episode (Sep 30), Andrew said: > > I'm counting traffic with ipfw and shell scripts. Is there a way to > > use more than 32-bit numbers in shell arithmetic? > > POSIX only requires "signed long" support in the shell, but FreeBSD's > expr command has a -e flag that will let it do 64-bit math: > > $ echo $(( 65536*65536 )) > 0 > $ echo $(expr 65536 "*" 65536) > 0 > $ echo $(expr -e 65536 "*" 65536) > 4294967296 > > bash, ksh93 (but not pdksh), and zsh's shell arithmetic are all 64-bit, > also. Thanks! I haven't thought about using expr. How come that my expr(1) manpage has nothing to say about -e option? In fact my expr(1) does not accept it. I have FreeBSD 4.10. I've just looked into a current manpage from www.freebsd.org, and it says something about 4.x compatibility. What is the best way to go if I need to write scripts now, but I'm planning to switch to 5.x later? Can I upgrade expr(1) now? If not, what should I do? Thanks again and regards, Andrew P.