bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mod arithmetic result 0 gives error exit status


From: Chris F.A. Johnson
Subject: Re: mod arithmetic result 0 gives error exit status
Date: Mon, 10 Oct 2005 20:24:06 -0400 (EDT)

On Mon, 10 Oct 2005, Duane Ellis wrote:

VERSION:
       GNU bash, version 3.00.15(1)-release (i386-redhat-linux-gnu)
       {came with Red Hat EL-4}

Description:

       Valid math operations results give an ERROR exit status.

While this is a documented feature [4.2 of the info file]

       If the last EXPRESSION evaluates to 0,
       `let' returns 1; otherwise 0 is returned.

grr grrr ... it was not expected, and bash treats it as an ERROR

       bash$ let A=1-1
       bash$ echo $?

     I treat "let" as an error, since it is not portable. Use the
     portable arithmetic syntax and you do not get an error:

A=$(( 1 - 1 ))


Info file: "6.5 Shell Arithmetic" where available operators are
listed implies that the only "error" that can occur is division by
zero.

       "[snip] with no check for overflow, though division
       by 0 is trapped and flagged as an error."

Implies otherwise.

Thanks.

Duane Ellis



_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


--
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]