Changes

Jump to: navigation, search

Tutorial12: Shell Scripting - Part 2

240 bytes added, 09:03, 5 September 2020
Additional Logic Statements
[[Image:if-elif-else.png|thumb|right|300px|Example of how an '''if-elif-else''' statement works.]]'''if-elif-else Statements'''
The '''elif''' statement can be used to perform additional conditional tests of the previous test condition tests FALSE. This statement is used to make your logic control-flow statement to be more adaptable.<br><br>''How it Works:''<br>If the test condition returns a TRUE value, then the Linux Commands between<br>then and else statements are executed.<br><br>If the test returns a FALSE value, then a new condition is tested,<br>and action is taken if the result is TRUE . Eventually, an action will be taken<br>when the final test condition is FALSE
''Example:''
<span style="font-family:courier;">num1=5<br>num2=10<br>if test $num1 –lt $num2<br>then &nbsp;&nbsp;&nbsp;echo “Less Than”<br>elif test $num1 –gt $num2<br>then<br> &nbsp;&nbsp;&nbsp;echo “Greater Than”<br>else &nbsp;&nbsp;&nbsp;echo “Equal to”<br>fi</span><br><br>
13,420
edits

Navigation menu