Question

NIT1202 Operating Systems UNIX Script You are required to write a Bourne Again Shell Script (bash)...

NIT1202 Operating Systems UNIX Script 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: Print the following user information: the home directory, path, userid , login shell together with the current date and time. Ask a user a range and it displays eight random number between the range. [Range difference must be 100. Example Enter a range: 200 300 Print out the highest and the lowest numbers of the generated eight random numbers Exit the program

0 0
Add a comment Improve this question Transcribed image text
Answer #1


echo "Print the following:"                    
ch=0;                                       
i=0;                                       
while [ $ch -lt 4 ]                               
do                                       
   echo "1.Show home directory"                      
   echo "2.display path"
   echo "3.display userid"
   echo "4.login shell"
   echo "Enter your choice"
   read ch                               
   case $ch in                              
   1)  
       pwd
       ;;                                  
   2)
       echo path                      
       ;;
   3)
       id -u <username>
       ;;
   4)
       sudo -s
       ;;
done
date
echo "Enter the range,starting first then ending"
s=0;
e=0;
small=0;
large=0;
no=0;
dif=0;
read s
read e
dif=e-s
if [ $dif -ne 100 ]
then
echo "Range should be with a difference of 100.Enter again"
read s
read e
fi
for i in 1,2,3,4,5,6,7,8
do
no=(($s + RANDOM % $e))
if [$no -gt $large]
then
$large=$no
fi
if [$no -lt $small]
then
$small=$sno
fi

echo "Largest and smallest no respectively:"

echo large

echo small
done

Explanation:

Using echo we have displayed the menu with four option and asked the user what he wants to do After that, we will use while loop to input from the user and run the desired option. In while we have specified the condition that while ch is less than 4, it will print the menu and take input form the user. After taking the input, using switch case the following options will be displayed. To print the home directory, pwd is used. On successful compilation, the current user directory will be displayed. To print the path echo path is used. To print userid id command is used and to login shell as sudo user sudo-s is used. After that the question demands to print the dat and time. Using simple date command the current date and time will be printed.Then the user is asked to input the range of the no which is stored as s and e. We store the difference of the two in diff. Then using if we check that the diff should be 100, not less not more. If the difference is more or less, in either case, we echo that range is not acceptable and that it should have difference100 and then ask the user to input the range again. Using random pre-defined keyword, we generate random no and we use for loop along with it so that it generate only 8 no. Then inside for loop we use two if loop, one to check the largest no and second smallest. With every random no generated we keep no checking it with previous one and if they are larger or smaller then we store them accordingly and finally at last outside the for loop we print the nos.

Add a comment
Know the answer?
Add Answer to:
NIT1202 Operating Systems UNIX Script You are required to write a Bourne Again Shell Script (bash)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT