Difference between revisions of "Bash if elif else fi"

From thelinuxwiki
Jump to: navigation, search
Line 1: Line 1:
 
Bash If..elif..else..fi
 
Bash If..elif..else..fi
  
   If [ conditional expression1 ]
+
   if [ conditional expression1 ]
 
   then
 
   then
 
     statement1
 
     statement1

Revision as of 15:50, 1 March 2017

Bash If..elif..else..fi

 if [ conditional expression1 ]
 then
   statement1
   statement2
   .
 elif [ conditional expression2 ]
 then
   statement3
   statement4
   .
   .
   .
 else
   statement5
 fi

example

 if [ "$opt" = "some string" ]; then
   some_command
 fi

OR example

 if [[ "$VARIABLE" == "something" || "$VARIABLE" == "else" ]]; then
   some_command
fi