Apr 11, 2011

bash if grammar or(||) and(&&) (if文の or and条件)

I had to check parameters.
I searched if grammar, but I couldn't get a example of if condition || condition.
So I changed key word for search. It was "condition expressions"
I've got the answer. OR condition is -o and AND condition is -a.
Here is the sample code.

OR condition

if ["$1" == "" -o "$2" == ""] ; then
  exit 1
fi

AND condition

if ["$1" == "" -a "$2" == ""] ; then
  exit 1
fi
Post a Comment