Date: Fri, 1 Oct 2004 00:09:24 +0400 From: "Andrew" <infofarmer@mail.ru> To: "Dan Nelson" <dnelson@allantgroup.com> Cc: freebsd-questions@freebsd.org Subject: Re: 64-bit arithmetic in scripts? Message-ID: <004901c4a729$61fc7810$4611a8c0@SATPC> References: <000601c4a720$99264270$4611a8c0@SATPC> <20040930194001.GD22530@dan.emsphone.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?004901c4a729$61fc7810$4611a8c0>