Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

936 bytes added, 2 March
Using Control Flow Statements in Shell Scripts
Refer to the diagram immediately to the right for using the '''if logic statement''' with the '''test''' command.
'''if-else statement:'''
[[Image:if-else.png|thumb|right|300px|Example of how an '''if-else''' statement works.<br>(Image licensed under [ cc])]]
Unlike using only an ''if'' statement, an '''if-else''' statement take '''two different sets of actions'''<br>based on the results of the test condition.<br><br>''How it Works:''<br>When the test condition returns a '''TRUE''' value, then the Linux Commands between<br>'''then''' and '''else''' statements are executed.<br>If the test returns a '''FALSE''' value, then the the Linux Commands between<br>the '''else''' and '''fi''' statements are executed.<br><br>
<span style="font-family:courier;font-weight:bold;">num1=5<br>num2=10<br>if test $num1 –lt $num2<br>then<br> &nbsp;&nbsp;&nbsp;echo “Less Than”<br>else<br>echo &nbsp;&nbsp;&nbsp;“Greater Than or Equal to”<br>fi</span><br><br>

Navigation menu