Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

823 bytes removed, 07:23, 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'''. The exit status '''$?''' shows a zero (TRUE) value, but the number 5 is definitely NOT greater than 10. 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 correctly issued test command used redirect to create an empty file instead, what 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;&equals), '''-gt''' (&gt;), '''-ge''' (&gt;'''NOTE:''' You will notice that something is '''wrong'''. The exit status '''$?''' shows a zero (TRUE) value, but the number 5 is definitely NOT greater than 10. 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 -1 5</span><br><br>You should notice an empty file called "'''5'''". The correctly issued test command used redirect to create an empty file instead, what 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;=), '''-gt''' (&gt;), '''-ge''' (&gt;=), '''-eq''' (=), '''-ne''' (!=)<br><br># x), '''-eq''' ('''NOTE:''' You will notice that something is '''wrong'''. The exit status '''$?''' shows a zero (TRUE) value, but the number 5 is definitely NOT greater than 10. 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 -1 5</span><br><br>You should notice an empty file called "'''5'''". The correctly issued test command used redirect to create an empty file instead, what 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;=), '''-gt''' (&gt;), '''-ge''' (&gt;=), '''-eq''' (=), '''-ne''' (!=)<br><br>
# x), '''-ne''' (!'''NOTE:''' You will notice that something is '''wrong'''. The exit status '''$?''' shows a zero (TRUE) value, but the number 5 is definitely NOT greater than 10. 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 -1 5</span><br><br>You should notice an empty file called "'''5'''". The correctly issued test command used redirect to create an empty file instead, what 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;=), '''-gt''' (&gt;), '''-ge''' (&gt;=), '''-eq''' (=), '''-ne''' (!=)<br><br>
13,420
edits

Navigation menu