UNIX Script Assignment: Part 2 - NIT1202 Operating Systems
Verified
Added on 2023/06/03
|9
|840
|374
AI Summary
This shell script generates different information such as home directory, path, userid, login shell with the current date and time, displays 8 random numbers between the range inputted by the user, prints out highest and lowest numbers of the eight random numbers generated and exits the program.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Running head: NIT1202 OPERATING SYSTEMS UNIX Script Assignment: Part 2 Trimester 2, 2018 Name of the Student Name of the University Author’s Note
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
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
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 "*******************************" }
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
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
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.Printingouthighestandlowestnumbersoftheeightrandomnumbers 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
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"
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
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
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.