#################################################
# IS380 Shell Scripting Midterm
# Date: 7/14/2021
#
# Total 100 points, 20% of your grade
#
# Name: -- your name here --
#
# Note: Before or by 8:10PM, you need to submit the following files:
# 1, this midterm.txt with your answers for question #1 and #2 in it
# 2, m3.sh
# 3, m4.sh
# 4, m5.sh
# 5, m6.sh
# 6, m7.sh (extra credit)
#################################################
1, (5 points) Please review the following shell script,
explain what's wrong with the code and fix the problems.
#!
in
ash
var1 = "What's wrong?"
echo $var1
2, (5 points) When do you use single quotes, double quotes? What's the differences?
3, (20 points) What are $, ( ), (( )), [ ], [[ ]] do in Bash shell?
Create runnable examples in a script m3.sh for each and use comment to explain each example.
4, (20 points) Write a script called m4.sh to
1) check if the directory "xyz" exists.
2) if it exists, create an empty file "checked" inside "xyz". Also print out
message "xyz exists. just checked"
3) if "xyz" does not exist, create "xyz" dir and an empty file "new" inside
"xyz". Then print out "xyz dir created. new"
5, (20 points) Let's say you want to rewrite an existing script m5_old.sh and execute
additional features and messages to make it more useful and user-friendly.
Say this is the way you run the script and its output:
% ./m5_old.sh World XXXXXXXXXX
**************************
Hello World!
XXXXXXXXXX
I am doing this and that.
**************************
% ./m5_old.sh Andy XXXXXXXXXX
**************************
Hello Andy!
XXXXXXXXXX
I am doing this and that.
**************************
You need to write a new script m5.sh that will maintain the same use model and
print out more useful information as below:
% ./m5.sh John XXXXXXXXXX
**************************
Hello John!
Date: 5/13/2020
User id: use
Cu
ent directory: /home/use
midterm
I am running: % ./m5.sh John XXXXXXXXXX
5 + 13 = 18
2020 / 13 = 155
I am still doing this and that.
**************************
6, (30 points) Write a script m6.sh. It will take a user
argument (positive integer) to print out the following
numbers pattern as shown below:
% ./m6.sh
Please enter a positive integer: 3
==============================================================
Printing 3 line(s) from 1 to 7
1
2 3
4 5 6 7
% ./m6.sh
Please enter a positive integer: 6
==============================================================
Printing 6 line(s) from 1 to 63
1
2 3
4 5 6 7
XXXXXXXXXX15
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
7, Extra credit (10 points) Make a copy of m6.sh to m7.sh.
For betterNum.sh, please add user input validation to restrict user input
to be a positive integer between 1 and 8.
If you didn't do or complete m6.sh problem (#10 question),
you may still create a simple standalone script to take a user input
(positive integer between 1 ~ 8) and validate the input value to
either print out
User input is: user_entered_numbe
O
E
or: invalid input: user_entered_number. Only positive integer 1 ~ 8 allowed.
#################################################
# IS380 Shell Scripting Midterm
# Date: 7/14/2021
#
# Total 100 points, 20% of your grade
#
# Name: -- your name here --
#
# Note: Before or by 8:10PM, you need to submit the following files:
# 1, this midterm.txt with your answers for question #1 and #2 in it
# 2, m3.sh
# 3, m4.sh
# 4, m5.sh
# 5, m6.sh
# 6, m7.sh (extra credit)
#################################################
1, (5 points) Please review the following shell script,
explain what's wrong with the code and fix the problems.
#!
in
ash
var1 = "What's wrong?"
echo $var1
2, (5 points) When do you use single quotes, double quotes? What's the differences?
3, (20 points) What are $, ( ), (( )), [ ], [[ ]] do in Bash shell?
Create runnable examples in a script m3.sh for each and use comment to explain each example.
4, (20 points) Write a script called m4.sh to
1) check if the directory "xyz" exists.
2) if it exists, create an empty file "checked" inside "xyz". Also print out
message "xyz exists. just checked"
3) if "xyz" does not exist, create "xyz" dir and an empty file "new" inside
"xyz". Then print out "xyz dir created. new"
5, (20 points) Let's say you want to rewrite an existing script m5_old.sh and execute
additional features and messages to make it more useful and user-friendly.
Say this is the way you run the script and its output:
% ./m5_old.sh World XXXXXXXXXX
**************************
Hello World!
XXXXXXXXXX
I am doing this and that.
**************************
% ./m5_old.sh Andy XXXXXXXXXX
**************************
Hello Andy!
XXXXXXXXXX
I am doing this and that.
**************************
You need to write a new script m5.sh that will maintain the same use model and
print out more useful information as below:
% ./m5.sh John XXXXXXXXXX
**************************
Hello John!
Date: 5/13/2020
User id: use
Cu
ent directory: /home/use
midterm
I am running: % ./m5.sh John XXXXXXXXXX
5 + 13 = 18
2020 / 13 = 155
I am still doing this and that.
**************************
6, (30 points) Write a script m6.sh. It will take a user
argument (positive integer) to print out the following
numbers pattern as shown below:
% ./m6.sh
Please enter a positive integer: 3
==============================================================
Printing 3 line(s) from 1 to 7
1
2 3
4 5 6 7
% ./m6.sh
Please enter a positive integer: 6
==============================================================
Printing 6 line(s) from 1 to 63
1
2 3
4 5 6 7
XXXXXXXXXX15
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
7, Extra credit (10 points) Make a copy of m6.sh to m7.sh.
For betterNum.sh, please add user input validation to restrict user input
to be a positive integer between 1 and 8.
If you didn't do or complete m6.sh problem (#10 question),
you may still create a simple standalone script to take a user input
(positive integer between 1 ~ 8) and validate the input value to
either print out
User input is: user_entered_numbe
O
E
or: invalid input: user_entered_number. Only positive integer 1 ~ 8 allowed.