13,420
edits
Changes
→INVESTIGATION 4: CONTROL FLOW STATEMENTS
# Issue the following Linux command to test a condition involving earlier assigned variables:<br><span style="color:blue;font-weight:bold;font-family:courier;">test $number1 > $number2</span><br><br>
# Issue a Linux command to display the value of '''$?'''<br><br>'''NOTE:''' You will notice that something is '''wrong'''.<br>The exit status '''$?''' shows a zero (TRUE) value, but the number 5 is definitely NOT greater than 10.<br>The problem is that the symbols '''<''' and '''>''' are interpreted as REDIRECTION symbols!<br><br>
# To prove this, issue the following Linux command :<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -l 10</span><br><br>You should notice a file called "'''10'''". The incorrectly issued '''test''' command '''used redirection'''<br>to create an empty file instead,<br> which indeed succeeded just giving a TRUE value!<br><br>To prevent problems when issuing the '''test''' command when comparing numbers, you can use the following options:<br>'''-lt''' (<), '''-le''' (<=), '''-gt''' (>), '''-ge''' (>=;), '''-eq''' (=), '''-ne''' (!=)<br><br>
# Issue the correct Linux command to properly test both values:<br><span style="color:blue;font-weight:bold;font-family:courier;">test $number1 -gt $number2</span><br><br>
# Issue a Linux command to display the value of '''$?'''.<br><br>You should notice that the exit status value is now FALSE which is the correct result.<br><br>