Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

77 bytes removed, 09:33, 3 September 2020
Using Control Flow Statements in Shell Scripts
<table align="right"><tr valign="top"><td>[[Image:test-1.png|thumb|right|140px|Examples of simple comparisons using the test command.]]</td><td>[[Image:test-2.png|thumb|right|140px|Examples of using additional comparisons using the test command.]]</td></table>
'''Control Flow Statement Statements''' are used to make your shell scripts more '''flexible ''' and can '''adapt ''' to changing situations.
The special parameter '''$?''' Is used to determine the '''exit status ''' of the previously issued Linux command.The exit status will either display a '''zero ''' (representing TRUE) or a '''non-zero ''' number (representing FALSE). This can be used to determined if a Linux command was correctly or incorrectly executed. The '''test''' Linux command is used to test conditions to see if they are '''TRUE''' (i.e. value '''zero''') or '''FALSE''' (i.e. value '''non-zero''') so they can be used with control flow statements to control the sequence of a shell script.
You CANNOT use the '''>''' or '''<''' symbols when using the test command since these are redirection symbols. Instead, you need to use options when performing numerical comparisons.
There are <u>other</u> comparison options that can be used with the test command such as testing to see if a regular file or directory pathname exists, or if the regular file pathname is –non-empty.
Refer to diagrams to the right involving some of the options used with the '''test''' command. Refer to the test man pages for a full list of options for the test command.
'''Logic Statements'''
</pre>
Refer to the diagram relating to logic statements diagrams on the right side for an exampleusing the if logic statement with the test command.
'''Loop Statements'''
13,420
edits

Navigation menu