Click to See Complete Forum and Search --> : how to make conditional statement in bash


hardigunawan
11-29-2000, 02:38 AM
how do i make a conditional statement in bash, similar to the c code below?

if(a==0 | | b==0) {
do something;
}

i was trying

if [ $A eq 0 | | $B eq 0]; then
do something;
fi

but it does not work http://www.linuxnewbie.org/ubb/frown.gif

Strike
11-29-2000, 03:00 AM
http://linuxnewbie.internet.com/nhf/intel/programming/introbashscript.html http://linuxnewbie.internet.com/nhf/intel/programming/bash_cheat.html
Two awesome references for ya.

----edit----
short answer: use -o instead of | |

[This message has been edited by Strike (edited 29 November 2000).]

hardigunawan
11-29-2000, 03:22 AM
thanks! never expected to get a reply so soon http://www.linuxnewbie.org/ubb/smile.gif

i used the 1st reference, which is [expr1] | | [expr2].

the one that uses -o cannot work when checking for arguments. eg.
[ -z $1 -o -z $2 ]

however, [ "$1x" = "x" -o "$2x" = "x" ] works.

thought i put my little experience here for others http://www.linuxnewbie.org/ubb/smile.gif