Changes

Jump to: navigation, search

Tutorial 10 - Shell Scripting - Part 1

3,382 bytes added, 13:47, 14 November 2021
LINUX PRACTICE QUESTIONS
= LINUX PRACTICE QUESTIONS =
The purpose of this section is to obtain '''extra practice''' to help with '''quizzes''', your '''midterm''', and your '''final exam'''.
 
Here is a link to the [https://matrix.senecacollege.ca/~osl640/questions/osl640_week10_practice.docx MS Word Document of ALL of the questions] displayed below but with extra room to answer on the document to
simulate a quiz:
 
 
Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).
 
 
'''Review Questions:'''
 
 
'''PART A: WRITE BASH SHELL SCRIPT CODE'''
 
'''Write the answer to each question below the question in the space provided.'''
 
 
# 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 '''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'''
 
'''Write the expected output from running each of the following Bash shell scripts You can assume that these Bash shell script files have execute permissions. Show your work.'''
 
:'''Walkthru #1:'''
 
:'''cat walkthru1.bash'''
<pre>
#!/usr/bin/bash
word1=”counter”
word2=”clockwise”
echo “The combined word is: $word2$word1”
</pre>
 
:WRITE ROUGH WORK AND OUTPUT FROM ISSUING:
:'''./walkthru1.bash'''
 
:ROUGH WORK:
 
:OUTPUT:
 
 
 
:'''Walkthru #2:'''
 
:'''cat walkthru2.bash'''
<pre>
#!/usr/bin/bash
echo “result1: $1”
echo “result2: $2”
echo “result3: $3”
echo “result 4:”
echo “$*”
</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:OSL640]]

Navigation menu