Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

917 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, 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 '''dogFactor''' to '''7'''. The script will then clear the screen and prompt the user to enter the age of a dog in human years (which will be stored into a variable called '''humanYears''').<br><br>The script will store in a variable called '''dogYears''' the value of ''humanYears x dogFactor''<br>The script will then clear the 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