Open main menu

CDOT Wiki β

Changes

Tutorial10: Shell Scripting - Part 1

3 bytes added, 08:10, 16 March 2021
INVESTIGATION 1: CREATING A SHELL SCRIPT
# '''Save''' your editing session and '''exit''' the text editor.<br><br>Instead of issuing the '''bash''' command followed by your shell script pathname as an ''argument'',<br>let's simply run it by its filename. This is the most common method of running shell scripts.<br><br><table align="right"><tr valign="top"><td>[[Image:no-execute.png|thumb|right|230px|An '''error message''' will appear when trying to run a shell script by name that does NOT have '''execute''' permissions.]]</td><td>[[Image:hello1.png|thumb|right|150px|Output from running your '''hello''' shell script (YourUserID representing <u>your</u> username).]]</td></table>
# Issue the following linux command to run your shell script in your current directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">./hello</span><br><br>You should notice an '''ERROR message''' indicating you don't have permissions to run the file. To fix this, you need to<br>'''add execute permissions''' prior to running the shell script.<br><br>
# Issue the following linux command to '''add''' execute permissions <br>for your shell script:<br><span style="color:blue;font-weight:bold;font-family:courier;">chmod u+x hello</span><br><br>
# Re-run your shell script: <span style="color:blue;font-weight:bold;font-family:courier;">./hello</span><br><br>Did your shell script run?<br><br><span style="color:red;">'''ATTENTION:''' Students might get FRUSTRATED when performing their '''assignment 3''' when their Bash shell scripts have errors. One major cause is the the OUTPUT of their Bash shell script when run does not '''EXACTLY match''' the required output for the correct Bash shell script. This requires that you CAREFULLY '''read''' the requirements of your Bash shell script and create it to the EXACT specifications</span><br><br>
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/myscripts/week10-check-1</span><br><br>
13,420
edits