Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are required to write a Bourne Again Shell Script (bash) to manage a menu dr

ID: 3589779 • Letter: Y

Question

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.

Explanation / Answer

while true
do
echo
echo "============================================================================================================="
echo "1. Print Home Directory,path, userid , login shell together with the current 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 ] : "
read 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 "Current Date&Time : `date`"   # date is a command, which displays both current 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 current 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
        for i in `seq 7`
         do
           R=$(($(($RANDOM%$dif))+$m))
           echo $R
           if [ $min -ge $R ] ; then
              min=$R
           fi
           if [ $max -le $R ] ; then
              max=$R
           fi
         done
      fi
      ;;
   3)
      echo "The minimum number from generated 8 random numbers : $min"
      echo "The maximum number from generated 8 random numbers : $max"
      ;;
   4) exit 1
      ;;
   *) echo "Invalid choice..."
esac
echo "============================================================================================================="
done   # End of while loop

<<'COMMENT'
lenovo@lenovo-Vbox:~/chegg$ chmod 777 menu.sh
lenovo@lenovo-Vbox:~/chegg$ ./menu.sh

=============================================================================================================
1. Print Home Directory,path, userid , login shell together with the current date and time.
2. Ask a user a range and it displays eight random number between the range. [Range difference must be 100.]
3. Print out the highest and the lowest numbers of the generated eight random numbers.
4. Exit the program Requirements
=============================================================================================================
Enter choice [ 1 - 4 ] :
1
Home Directory : /home/lenovo
Path           : /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
User Id        : 1000
Login Shel     : /bin/bash
Current Date&Time : Mon Oct 9 22:29:13 IST 2017
=============================================================================================================

=============================================================================================================
1. Print Home Directory,path, userid , login shell together with the current date and time.
2. Ask a user a range and it displays eight random number between the range. [Range difference must be 100.]
3. Print out the highest and the lowest numbers of the generated eight random numbers.
4. Exit the program Requirements
=============================================================================================================
Enter choice [ 1 - 4 ] :
2
Enter starting range :
100
Enter ending range :
60
60 - 100 difference is -40
the difference should be Hundered
=============================================================================================================

=============================================================================================================
1. Print Home Directory,path, userid , login shell together with the current date and time.
2. Ask a user a range and it displays eight random number between the range. [Range difference must be 100.]
3. Print out the highest and the lowest numbers of the generated eight random numbers.
4. Exit the program Requirements
=============================================================================================================
Enter choice [ 1 - 4 ] :
2
Enter starting range :
100
Enter ending range :
300
300 - 100 difference is 200
the difference should be Hundered
=============================================================================================================

=============================================================================================================
1. Print Home Directory,path, userid , login shell together with the current date and time.
2. Ask a user a range and it displays eight random number between the range. [Range difference must be 100.]
3. Print out the highest and the lowest numbers of the generated eight random numbers.
4. Exit the program Requirements
=============================================================================================================
Enter choice [ 1 - 4 ] :
2
Enter starting range :
200
Enter ending range :
300
Eight Random Integers between 300 and 200 are ...
256
270
251
262
290
214
258
278
=============================================================================================================

=============================================================================================================
1. Print Home Directory,path, userid , login shell together with the current date and time.
2. Ask a user a range and it displays eight random number between the range. [Range difference must be 100.]
3. Print out the highest and the lowest numbers of the generated eight random numbers.
4. Exit the program Requirements
=============================================================================================================
Enter choice [ 1 - 4 ] :
3
The minimum number from generated 8 random numbers : 214
The maximum number from generated 8 random numbers : 290
=============================================================================================================

=============================================================================================================
1. Print Home Directory,path, userid , login shell together with the current date and time.
2. Ask a user a range and it displays eight random number between the range. [Range difference must be 100.]
3. Print out the highest and the lowest numbers of the generated eight random numbers.
4. Exit the program Requirements
=============================================================================================================
Enter choice [ 1 - 4 ] :
6
Invalid choice...
=============================================================================================================

=============================================================================================================
1. Print Home Directory,path, userid , login shell together with the current date and time.
2. Ask a user a range and it displays eight random number between the range. [Range difference must be 100.]
3. Print out the highest and the lowest numbers of the generated eight random numbers.
4. Exit the program Requirements
=============================================================================================================
Enter choice [ 1 - 4 ] :
4

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote