NIT1202 Operating Systems: Menu-Driven UNIX Shell Script Assignment

Verified

Added on  2023/06/03

|9
|840
|374
Homework Assignment
AI Summary
This assignment solution presents a Bourne Again Shell (bash) script designed to manage a menu-driven program, fulfilling the requirements of the NIT1202 Operating Systems course. The script offers four options: displaying user information (home directory, path, user ID, login shell, date, and time), generating eight random numbers within a user-specified range (with a difference of 100), identifying the highest and lowest numbers from the generated set, and exiting the program. The script incorporates functions, conditional statements, and loops to provide a user-friendly interactive experience, with error handling for invalid menu selections. The solution demonstrates proficiency in shell scripting, meeting all specified criteria and providing a comprehensive example for students studying operating systems and shell programming. The provided code is well-commented, explaining the purpose and function of each section of the script.
Document Page
Running head: NIT1202 OPERATING SYSTEMS
UNIX Script Assignment: Part 2
Trimester 2, 2018
Name of the Student
Name of the University
Author’s Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1
NIT1202 OPERATING SYSTEMS
Table of Contents
1. Bourne Again Shell Script for the management of menu driven program......................2
1.1. Print the user information: the home directory, path, user id, login shell together
with the current date and time.....................................................................................................2
1.2. Shell program displaying 8 random number between the range inputted by the user
(Range difference of 100)............................................................................................................3
1.3. Printing out highest and lowest numbers of the eight random numbers generated. .4
1.4. Exit the program.......................................................................................................6
Bibliography........................................................................................................................7
Document Page
2
NIT1202 OPERATING SYSTEMS
1. Bourne Again Shell Script for the management of menu driven program
1.1. Print the user information: the home directory, path, user id, login shell
together with the current date and time
#!/bin/bash
#Author's Name: Student
#Student_ID s12345
#Date: Oct 2018
#This script generates different information such as
# home directory, path, userid, login
# shell with the current date and time
# function for displaying a line of asterics
echo "Please choose any of the options"
option=("Option 1" "Option 2" "Option 3" "Option 4")
select option in "${option[@]}"
do
function ln(){
echo "*******************************"
}
Document Page
3
NIT1202 OPERATING SYSTEMS
case $option in
"Option 1") clear
echo "Display the home directory : $(ls)"
ln # function called
echo "Diplay the path : $(echo $PATH)"
ln
echo "userid : $(id -u)"
ln
echo "login shell with current date and time:"
who
ln ;;
1.2. Shell program displaying 8 random number between the range inputted by the
user (Range difference of 100)
"Option 2")
#This script is created to accept a range
#From user and display eight random numbers between the range
#Author: Student_Name
#Student_ID s12345
#Date: Oct 2018
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4
NIT1202 OPERATING SYSTEMS
echo "Enter the range and the difference must be 100:"
read upper
read lower
ln
echo "The random numbers between the range $upper and $lower is as follows: "
IFS=$'\n'
num=($(shuf -i $upper-$lower -n 8))
printf "%s\n" "${num[@]}"
ln
;;
1.3. Printing out highest and lowest numbers of the eight random numbers
generated
"Option 3")
#The shell script is created for displaying
#Maximum and the minimum number from the random numbers
#Generated in the above option
#Author's Name: Student_Name
#Student_ID s12345
#Date: Oct 2018
Document Page
5
NIT1202 OPERATING SYSTEMS
echo "The random numbers generated are as follows:"
IFS=$'\n'
#num=($(shuf -i $upper-$lower -n 8))
printf "%s\n" "${num[@]}"
ln
minimum=${num[0]}
maximum=${num[0]}
# Loop for the elements in the created array
for i in "${num[@]}"
do
# Printing the minimum number from the range
if [[ "$i" -lt "$minimum" ]]; then
minimum="$i"
fi
# Printing the maximum number from the range
if [[ "$i" -gt "$maximum" ]];
then
maximum="$i"
Document Page
6
NIT1202 OPERATING SYSTEMS
fi
done
echo "The lower number from the range is: $minimum"
ln
echo "The highest number from the range is: $maximum"
ln
;;
1.4. Exit the program
"Option 4")
#This shell script exits the loop
#Author's Name: Kiran Gautam
#Student_ID s458158
#Date: Oct 2017
break
;;
*) echo "Entry is invalid"
;;
esac
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7
NIT1202 OPERATING SYSTEMS
done
Document Page
8
NIT1202 OPERATING SYSTEMS
Bibliography
Cannon, J. (2015). Shell Scripting: How to Automate Command Line Tasks Using Bash
Scripting and Shell Programming.
Greenberg, M. (2017). Understanding the POSIX shell as a programming language. Off the
Beaten Track.
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]