LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   multiple if condition in bash (https://www.linuxquestions.org/questions/programming-9/multiple-if-condition-in-bash-682574/)

tikit 11-11-2008 03:37 AM

multiple if condition in bash
 
Hi,

how can I write this multiple condition in a bash script?

Code:

if ((a > 30) || ((a < 0) && (b > 30))) then ...
Thanks for your help.

tikit

colucix 11-11-2008 05:08 AM

You have to nest a double parenthesis construct like this:
Code:

if (( a > 30 || (( a < 0 && b > 30 )) )) ; then

w3bd3vil 11-11-2008 05:09 AM

aargh...colucix got to it before I did.

colucix 11-11-2008 05:11 AM

Quote:

Originally Posted by w3bd3vil (Post 3338150)
aargh...colucix got to it before I did.

he he he... ;)

tikit 11-11-2008 06:23 AM

Thanks. It works!.

chrism01 11-11-2008 05:54 PM

You appear to be trying to do numeric comparisons, in which case you're using the wrong operators. See http://www.tldp.org/LDP/abs/html/comparison-ops.html
:)

jan61 11-12-2008 01:34 PM

Moin,

Quote:

Originally Posted by chrism01 (Post 3338834)
You appear to be trying to do numeric comparisons, in which case you're using the wrong operators. See http://www.tldp.org/LDP/abs/html/comparison-ops.html
:)

not in the bash. See "man bash":
Code:

      ((expression))
              The  expression is evaluated according to the rules described below under ARITH-
              METIC EVALUATION.  If the value of the expression is non-zero, the return status
              is  0;  otherwise  the  return  status  is 1.  This is exactly equivalent to let
              "expression".
...
ARITHMETIC EVALUATION
      The  shell  allows  arithmetic expressions to be evaluated, under certain circumstances
      (see the let builtin command and Arithmetic Expansion).  Evaluation is done  in  fixed-
      width  integers with no check for overflow, though division by 0 is trapped and flagged
      as an error.  The operators and their precedence and associativity are the same  as  in
      the C language
.
...
      <= >= < >
              comparison
...
      &&    logical AND
      ||    logical OR

Jan


All times are GMT -5. The time now is 01:12 PM.