13,420
edits
Changes
→INVESTIGATION 3: exit AND break STATEMENTS
# Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">echo $?</span><br><br>
# Issue the following Linux command to confirm that stderr was redirected to a file:<br><span style="color:blue;font-weight:bold;font-family:courier;">cat error.txt</span><br><br>
'''THE BREAK STATEMENT'''
The '''break''' statement is used to '''terminate''' a loop.<br>
Although the loop terminates, the shell script will CONTINUE running.�
<br><br>
'''Perform the Following Steps:'''
# Make certain that you are logged into matrix account.<br><br>
# Confirm that you are currently located in the '''advanced''' directory.<br><br>
# Use a text editor like vi or nano to create the text file called '''exit.bash''' (eg. <span style="color:blue;font-weight:bold;font-family:courier;">vi exit.bash</span>)<br><br>
# Enter the following lines in the '''exit.bash''' shell script:<br><span style="font-family:courier;font-weight:bold;">#!/bin/bash<br><br>if [ $# -ne 1 ]<br>then<br> echo "USAGE: $0 [arg]" >&2<br>exit 1<br>fi<br><br>echo "The argument is: $1"</span><br><br>
# Save your editing session and exit the text editor (eg. with vi: press '''ESC''', then type ''':x''' followed by '''ENTER''').<br><br>
# '''Add execute permissions''' for this Bash shell script.<br><br>
# Issue the following command (without arguments):<br><span style="color:blue;font-weight:bold;font-family:courier;">./exit.bash</span><br><br>What did you notice?<br><br>Since there are no arguments, the test within the running shell script returns FALSE,<br>then an '''error message''' with feedback of how to properly issue the shell script with an argument<br>and then '''terminates''' the Bash shell script.<br><br>The symbol '''>&2''' redirects '''standard output''' from the USAGE message<br>to '''standard error''' making like a <u>real</u> error message.<br>This "''neat redirection trick''" will NOT be considered for evaluation for this coverage.<br><br>
=INVESTIGATION 4: USING START-UP FILES =