Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

You are required to write a Bourne Again Shell Script (bash) to manage a menu driven program. When executed the user should be presented with a menu with 4 (four) options: 1. Print the following user...

1 answer below »
You are required to write a Bourne Again Shell Script (bash) to manage a menu driven program. When executed the user should be presented with a menu with 4 (four) options: 1. Print the following user information: the home directory, print files and folder in column format, user id, login shell together with the current date and time. 2. Write a bash script program that reads a set of positive integer numbers until a sentinel value is entered. Enter –99 as the sentinel value to terminate the loop. The idea of a sentinel controlled loop is that there is a special value (the "sentinel") that is used to say when the loop is done. In this example, the user will enter -99 to tell the program to terminate the loop. 3. Print out the sum, the highest number and the lowest number of the entered numbers. 4. Exit the program
Document Preview:

NIT1202 Operating Systems UNIX Script Assignment 1: Part II Semester 2, 2017 For this assignment, you may work with one partner from the same lab, if desired. Objective: The aim of this assessment is to understand how to write basic menu driven bash scripts. Tasks: You are required to write a Bourne Again Shell Script (bash) to manage a menu driven program. When executed the user should be presented with a menu with 4 (four) options: 1. Print the following user information: the home directory, print files and folder in column format, user id, login shell together with the current date and time. 2. Write a bash script program that reads a set of positive integer numbers until a sentinel value is entered. Enter –99 as the sentinel value to terminate the loop. The idea of a sentinel controlled loop is that there is a special value (the "sentinel") that is used to say when the loop is done. In this example, the user will enter -99 to tell the program to terminate the loop. 3. Print out the sum, the highest number and the lowest number of the entered numbers. 4. Exit the program. Requirements: Your script must allow one of these options to be chosen at a time. The menu must be presented repeatedly, until the fourth option (exit) is chosen. An appropriate error message must be displayed if an invalid option is chosen. Option one, your script should list the specified environment variables - the home directory, print files and folder in column format, user id, login shell together with the current date and time. Option two should read a set of positive integer numbers until the sentinel value (-99) is entered. Option three should print the sum, the highest and the lowest number of the entered numbers. Option four should cause a graceful exit from the menu and the whole program. To Be Handed in: • A copy of your working bash shell script needs to be handed in to your tutor and uploaded in VU...

Answered 128 days After May 14, 2022

Solution

Ajay answered on Sep 19 2022
67 Votes
1 | P a g e

while true
do
echo
echo
"==============================================================================================
==============="
echo "1. Print Home Directory,path, userid , login shell together with the cu
ent date and time."
echo "2. Ask a user a range and it displays eight random number between the range. [Range difference must be
100.]"
echo "3. Print out the highest and the lowest numbers of the generated eight random numbers."
echo "4. Exit the program Requirements"
echo
"==============================================================================================
==============="
echo "Enter choice [ 1 - 4 ] : "
ead ch
case $ch in
1)
echo "Home Directory : $HOME" # HOME is pre-defined shell variable which will prints the home directory of
the user
# $ is symbol, which gives the value of the variable name
echo "Path : $PATH" # PATH is also a pre-deinfed shell variable which will prints the set of directories
separted by the colon
echo "User Id : $UID " # UID is pre-defined shell variable which will prints the numeric value of an unix
user loign id;;
echo "Login Shel : $SHELL" # SHELL is pre-defined shell variable which will prints the default shell of the user
echo "Cu
ent Date&Time : `date`" # date is a command, which displays both cu
ent system date and time
# the command date is enclosed with in a back quotations - it is a command substituion
feature
;;
2) echo "Enter starting range : "
read m
echo "Enter ending range : "
read n
dif=$(($n-$m))
if [ $dif -ne 100 ] ; then
echo "$n - $m difference is $dif"
echo "the difference should be Hundered"
else
dif=$(($dif + 1))
RANDOM=
#
is a pre-defined shell variable, which will gives process id of the cu
ent shell script
min=$(($(($RANDOM%$dif))+$m)) # the random number is mod with 100, so, we will get two digit number.
# This two digit number is added to the starting range of number,which is obviously
# between starting range and ending range.
max=$min
echo "Eight Random Integers between $n and $m are ..."
echo $min
2 | P a g e

for i in `seq 7`
do
R=$(($(($RANDOM%$dif))+$m))
echo $R
if [ $min -ge $R ] ; then
min=$R
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here