How to check multiple conditons in a IF statement
7,550
Solution 1
You have too many brackets, and the if
should not be capitalized. Try like this:
if [[ "$var1" == "$var2" || "$var1" == "$var3" || "$var1" == "$var4" ]]; then
Solution 2
Might be easier to use the standard sh
syntax rather than that (mispelled, it should be [[
instead of [[[
) ksh
construct:
case $var1 in
"$var2" | "$var3" | "$var4") echo match;;
*) echo no match;;
esac
Author by
Vimal Kumar
Updated on September 18, 2022Comments
-
Vimal Kumar almost 2 years
I am trying to test for multiple conditions in the following
if
statement:If [[[ "$var1" = "$var2" || "$var1" = "$var3" || "$var1" = "$var4" ]]];
However, when I execute the above mentioned syntax I am getting an error. Can anyone help me in getting multiple conditions checking in IF statement?