LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Or / And Condition in linux (https://www.linuxquestions.org/questions/linux-newbie-8/or-and-condition-in-linux-765307/)

soumyacs 10-29-2009 09:12 AM

Or / And Condition in linux
 
Hi All,

how to write or / and condition in if clause .

I want to write this type of logic

if [ "$var"="" or "$var1"="" ]
then
...........
else
.........
fi


Is it possible to write such type of logic here??

Thanks in advance

Berhanie 10-29-2009 10:05 AM

From the bash man page:
Code:

      [ expr ]
              Return a status of 0 or 1 depending on  the  evaluation  of  the
              conditional  expression expr. 
              ...
              expr1 -a expr2
                    True if both expr1 and expr2 are true.
              expr1 -o expr2
                    True if either expr1 or expr2 is true.
              ...


boondocksaint 10-29-2009 10:39 AM

Quote:

Originally Posted by soumyacs (Post 3736652)
Hi All,

how to write or / and condition in if clause .

I want to write this type of logic

if [ "$var"="" or "$var1"="" ]
then
...........
else
.........
fi


Is it possible to write such type of logic here??

Thanks in advance

if you're looking for efficiency, the above will work..if you want to keep the if statement,
Code:

if [ "$var"=""  or "$var1"="" ]
then
...........
elsif [ "$var"!="" or "$var1"!="" ]
.........
fi



All times are GMT -5. The time now is 07:14 PM.