Example: Bash if and or Condition

By | February 15, 2012

So, here is simple example that does simple “and” (-a) “or” (-o) conditioning for the “if” loop in bash shell scripting. The following script prints “DONE” if the condition is satisfied.

#!/bin/bash

# Example for using and (-a) in bash.
a1=3
b1=4
if [ $a1 -eq 3 -a $b1 -eq 4 ]; then
echo “DONE”
fi

#!/bin/bash

# Example for using or (-o) in bash.
a1=3
b1=3
if [ $a1 -eq 3 -o $b1 -eq 4 ]; then
echo “DONE”
fi

If you like this article, then please consider sharing it. Sharing really inspires us to do things much better!!

Leave a Reply

Your email address will not be published. Required fields are marked *