Re: 64-bit arithmetic in scripts?

From: Dan Nelson (dnelson_at_allantgroup.com)
Date: 09/30/04

  • Next message: Christian Hiris: "Re: How do you know how to install ports? (like vmware3)"
    Date: Thu, 30 Sep 2004 14:40:01 -0500
    To: Andrew <infofarmer@mail.ru>
    
    

    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@allantgroup.com
    _______________________________________________
    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: Christian Hiris: "Re: How do you know how to install ports? (like vmware3)"

    Relevant Pages

    • Re: how to make function known to subshell
      ... What do I have to do to make a function available in shell scripts or ... When a command is parsed the first word will be checked against the ... In the Korn Shell, there are two separate syntaxes for defining ...
      (comp.unix.shell)
    • Re: ruby shell?
      ... If it had not all ready been largely done in C, Perl, Lisp, and KornShell ... versions I'd probably work on a shell and posix oriented userland for fun. ... The scripts i write are _bourne_ shell scripts, ... Unix utilities have been rewritten as Korn Shell scripts and it even can be ...
      (comp.lang.ruby)
    • Re: [ANN] Protect you Unix Shell Scripts!
      ... > Shell scripts are very powerful tools for UNIX development. ... Upon execution, the compiled binary will ... you don't need an interpreter. ...
      (comp.os.linux.portable)
    • Re: [ANN] Protect you Unix Shell Scripts!
      ... > Shell scripts are very powerful tools for UNIX development. ... Upon execution, the compiled binary will ... you don't need an interpreter. ...
      (comp.os.linux.questions)
    • Re: [ANN] Protect you Unix Shell Scripts!
      ... > Shell scripts are very powerful tools for UNIX development. ... Upon execution, the compiled binary will ... you don't need an interpreter. ...
      (comp.os.linux.security)