Changes

Jump to: navigation, search

Tutorial12: Shell Scripting - Part 2

No change in size, 08:47, 30 July 2020
INVESTIGATION 2: ADDITIONAL LOOPING STATEMENTS
# Run your shell script by issuing: <span style="color:blue;font-weight:bold;font-family:courier;">./if-5.bash </span><br><br>When prompted, enter a letter instead of a number. What happens?<br><br>Let's edit the if-5.bash shell script to perform error-checking to force the user to enter a numeric value between 0 and 100.<br><br>
# Use a text editor like vi or nano to edit the text file called '''if-5.bash''' (eg. <span style="color:blue;font-weight:bold;font-family:courier;">vi if-5.bash</span>)<br><br>If you are using the nano text editor, refer to notes on text editing in a previous week in the course schedule.<br><br>
# Add the following lines in your shell script <u>AFTER</u> the read statement to prompt the user for a mark:<br><span style="font-family:courier;">#!/bin/bash<br>clear<br>while ! echo Here are files in my current directory:$mark | egrep "^[0-9]{1,}$"<br>echo<br/dev/null 2>for x in $(ls)/dev/null<br>do<br>&nbsp;&nbsp;&nbsp;echo read -p " &nbsp;&nbsp;&nbsp;$xNot a valid number. Enter a mark (0-100): "mark<br>done<br></span><br><br>
# Save your editing session and exit the text editor (eg. with vi: press '''ESC''', then type ''':wx''' followed by '''ENTER''').<br><br>
13,420
edits

Navigation menu