Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

870 bytes added, 19:42, 10 May 2021
INVESTIGATION 1: CREATING A SHELL SCRIPT
=INVESTIGATION 1: CREATING A SHELL SCRIPT=
<span style="color:red;">'''ATTENTION''': Depending on your ULI101 instruction, you may be required to complete this tutorial for marks in the course.<br>Please refer to your instructor's course notes in terms of marked assigned to the course.<br><br>The due date for successfully completing this tutorial (i.e. '''tutorial 10''') is by '''Friday by midnight''' next week (i.e. '''Week 10''').<br>If your instructor has NOT assigned marks for completing this tutorial, you can perform it for practice purposes.</span><br><br> 
In this investigation, you will learn how to create and run a '''Bash Shell script'''.
# Write a Bash shell script that clears the screen and displays the text Hello World on the screen.<br><br>What '''permissions''' are required to run this Bash shell script?<br>What are the different methods that you can run this Bash shell script from the command line?<br><br>
# Write a Bash shell script that clears the screen, prompts the user for their '''full name''' and then prompts the user for their '''age''', then clears the screen again and welcomes the user by their name and tells them their age.<br><br>What '''comments''' would you add to the above script’s contents to properly document this Bash shell script to be understood for those users that would read / edit this Bash shell script’s contents?<br><br># Write a Bash shell script that will first set the value of a read-only variable called '''numberdogFactor''' to '''23''' and make this variable '''read-only7'''.<br>Then the The script will then clear the screen and prompt the user to enter a value for that variable called number to another value.<br>Have the script display the value age of the a dog in human years (which will be stored into a variable called number to prove that it is a read-only variable'''humanYears''').<br><br>When you ran this Bash shell The script, did you encounter an error message?will store in a variable called '''dogYears''' the value of ''humanYears x dogFactor''<br>How would you run this Bash shell The script, so will then clear the error message was NOT displayed?screen a second time and then display the age of the dog in ''“dog years”''.<br><br># Write a Bash shell script that will clear the screen and then display all '''arguments ''' that were entered <u>after </u> your Bash shell script when it was run. Also have the Bash shell script display the '''number of arguments ''' that were entered after your Bash shell script.<br><br><br>
'''PART B: WALK-THRUS'''
</pre>
:WRITE ROUGH WORK AND OUTPUT FROM ISSUING:
:'''./walkthru1.bash'''
 
:ROUGH WORK:
 
:OUTPUT:
 
</pre>
:WRITE ROUGH WORK AND OUTPUT FROM ISSUING:
:'''./walkthru2.bash apple orange banana'''
 
:ROUGH WORK:
 
:OUTPUT:
 
<br><br>
:'''Walkthru #3:'''
 
:'''cat walkthru2.bash'''
<pre>
#!/usr/bin/bash
 
for x in 1 2 3 4 5
do
 
if [ $((x % 2)) -eq 0 ]
then
echo "this"
else
echo "that"
fi
 
done
 
</pre>
 
:WRITE ROUGH WORK AND OUTPUT FROM ISSUING:
:'''./walkthru3.bash apple orange banana'''
 
:ROUGH WORK:
 
:OUTPUT:
[[Category:ULI101]]
13,420
edits

Navigation menu