Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

1 byte removed, 07:34, 20 July 2020
INVESTIGATION 3: USING CONTROL FLOW STATEMENTS IN SHELL SCRIPTS
# Issue a linux command to display the value of '''$?'''. '''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 '''&lt;''' and '''&gt;''' 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 5</span><br><br>You should notice a file called "'''5'''". The incorrectly issued '''test''' command used redirect to create an empty file instead,<br> which indeed succeeded just giving a TRUE value!<br><br>To prevent these incorrectly issued testing for number comparison, you can use the following options instead:<br>'''-lt''' (&lt;), '''-le''' (&lt;&#61;), '''-gt''' (&gt;), '''-ge''' (&gt;&#61;;), '''-eq''' (&#61;), '''-ne''' (!&#61;)<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 '''$?'''. You should notice that the exit status value is now FALSE which is the correct result.<br><br>
# x
13,420
edits

Navigation menu