64-bit arithmetic in scripts?
Dan Nelson
dnelson at allantgroup.com
Thu Sep 30 12:40:06 PDT 2004
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.
--
Dan Nelson
dnelson at allantgroup.com
More information about the freebsd-questions
mailing list