Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

1,193 bytes removed, 04:33, 29 April 2022
no edit summary
# 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'''<br>execute permissions for your shell script:<br><span style="color:blue;font-weight:bold;font-family:courier;">chmod u+x hello</span><br><br>
# Issue the following to run your shell script:<br><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.<br>One major cause is the the OUTPUT of their Bash shell script when run does not '''EXACTLY match''' the required output<br>for the '''correct''' Bash shell script.<br><br>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;">~uli101/week10-check-1</span><br><br>
# If you encounter errors, make corrections and '''re-run''' the checking script until you<br>receive a congratulations message, then you can proceed.<br><br>
# Issue the following to run your Bash shell script just by name:<br><span style="color:blue;font-weight:bold;font-family:courier;">hello.bash</span><br><br>Did your Bash shell script run?<br><br>
# Exit your Matrix session, and log back into your Matrix session.<br><br>
# Re-run the '''hello.bash''' shell script by just using the name.<br><br>What did you notice?<br><br>The setting of the '''PATH''' environment variable only worked in the current session only.<br>If you exit the current Matrix session, then the recently changed settings for environment variables will be lost.<br>You will in a <u>future</u> tutorial how to set environment variables in '''start-up''' files.<br><br><span style="color:red;">'''ATTENTION:''' Students might get FRUSTRATED when performing their '''assignment 3''' when their Bash shell scripts have errors.<br>One major cause is the the OUTPUT of their Bash shell script when run does not '''EXACTLY match''' the required output<br>for the '''correct''' Bash shell script.<br><br>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;">~uli101/week10-check-2 | more</span><br><br>If you encounter errors, make corrections and '''re-run''' the checking script until you<br>receive a congratulations message, then you can proceed.<br><br>Unlike '''Environment variables''' that are used to set the environment of the shell or shell scripts,<br>'''User-created''' variables are "customized" that the user can set or allow a user to set the variables' values.<br>Let's create a Bash shell script that contain '''user-created variables'''.<br><br>
# Use a text editor to create a Bash shell script called '''user-variables.bash'''<br><br>
# Run your shell script by issuing:<br><span style="color:blue;font-weight:bold;font-family:courier;">./for-2.bash 10 9 8 7 6 5 4 3 2 1</span><br><br>How does this differ from the previous shell script?<br>You will learn in a couple of weeks more examples of using loop statements.<br><br>Let's run a '''checking-script''' to confirm that both your '''for-1.bash''' and '''for-2.bash'''<br><br>
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week10-check-4 | more</span><br><br>If you encounter errors, make corrections and '''re-run''' the checking script until you<br>receive a congratulations message, then you can proceed.<br><br>
# After you complete the Review Questions sections to get additional practice, then work on your '''online assignment 3''',<br>'''sections 2 and 3''' labelled '''Interactive Shell Environment''' and '''Introduction To Scripting (phone)'''.<br><br>
= LINUX PRACTICE QUESTIONS =
13,420
edits

Navigation menu