Part 2 - Linux Shell Scripting - Worth 5 points -Create a sh file named: program
ID: 3891253 • Letter: P
Question
Part 2 - Linux Shell Scripting - Worth 5 points -Create a sh file named: program2.sh - Set the permissions for this this .sh file using this command to - program2.sh should append your name and the current date and time program2.sh should then do the following: make it executable: chmod 755 *.sh to a NEW file called results.txt How: -Ask the user to enter a number - Verify that the number is between 1 and 50, inclusive. - If the number is not between 1 and 50, then keep asking the user to enter a number until it is valid. - Use a loop from 1 to the value entered by the user - Sum the results of all the included numbers, but do not include any output yet. After the loop ends, display the sum and append it to the results.txt file on a new line as follows Sum of numbers is xxx Zip your files into one file named FirstnameLastnameA2.zip submit them in the Assignment 2 dropbox Only include the folowing files: MemoryCalculator.java program2.sh Do not include any other files or folders in your submission Note that a Java program that does not compile and run and do something useful will earn 0 points. A shell script that does not do any part of the assignment will not earn any points eitherExplanation / Answer
Write your name in place of your_name in the code:
Here is the program2.sh file:
#!/bin/bash
echo your_name > results.txt
today=`date '+%Y-%m-%d--%H:%M:%S'`;
echo $today >> results.txt
echo "Please enter a number:"
read number
while [ $number -lt 1 ] || [ $number -gt 50 ];do
echo "Please enter a number:"
read number
done
i=1
sum=0
#I am assuming the user-input number has to be included in the sum
while [ $i -lt `expr $number + 1` ];do
sum=`expr $sum + $i`
((i++))
done
echo $sum
echo $sum >> results.txt
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.