################################################# # IS380 Shell Scripting Midterm # Date: 7/14/2021 # # Total 100 points, 20% of your grade # # Name: -- your name here -- # # Note: Before or by...

1 answer below »
number 1 and 2 are in the same .sh file and the rest of the questions are in there own seperate .sh file i have been using CoCalc


################################################# # 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. #!/bin/bash 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 7 14 2021 ************************** Hello World! 7 14 2021 I am doing this and that. ************************** % ./m5_old.sh Andy 5 1 2020 ************************** Hello Andy! 5 1 2020 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 5 13 2020 ************************** Hello John! Date: 5/13/2020 User id: user Current directory: /home/user/midterm I am running: % ./m5.sh John 5 13 2020 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 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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_number Or Error: 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. #!/bin/bash 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 7 14 2021 ************************** Hello World! 7 14 2021 I am doing this and that. ************************** % ./m5_old.sh Andy 5 1 2020 ************************** Hello Andy! 5 1 2020 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 5 13 2020 ************************** Hello John! Date: 5/13/2020 User id: user Current directory: /home/user/midterm I am running: % ./m5.sh John 5 13 2020 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 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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_number Or Error: invalid input: user_entered_number. Only positive integer 1 ~ 8 allowed.
Answered 16 days AfterJul 15, 2021

Answer To: ################################################# # IS380 Shell Scripting Midterm # Date: 7/14/2021...

Sampada answered on Jul 15 2021
139 Votes
#echo Please enter a positive integer:
#read p
p=5;
i="1";
j="0";
k="0"
for((m=1; m<=p;
m++))
do
k=$[2**j];
for((n=1; n<=m; n++))
do

echo -ne "$m ";
i=$[$i+1];

done
j=$[$j+1];
echo;
done
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here