Re: 64-bit arithmetic in scripts?

From: Andrew (infofarmer_at_mail.ru)
Date: 09/30/04

  • Next message: RJ45: "problems with FreeBSD-5.1 any progam goes core"
    To: "Dan Nelson" <dnelson@allantgroup.com>
    Date: Fri, 1 Oct 2004 00:09:24 +0400
    
    

    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.

    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"


  • Next message: RJ45: "problems with FreeBSD-5.1 any progam goes core"