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
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.
NIT1202 Operating Systems UNIX Script You are required to write a Bourne Again Shell Script (bash)...
BCS 215 (Unix Operating Systems) Create a bash shell script that displays a coffee vending machine menu and asks the user to make a choice - 1. Print "Please enter your choice: decaf|regular|latte|cappuccino" 2. Depending on the user input, print out the related price - decaf: 2 dollars regular: 2 dollars latte: 3 dollars cappuccino: 3 dollars For anything else, please display "Please make a valid choice." 3. Upon a successful execution of the script, display "Thank you for using...
Programs/scripts 13. Write a bash shell script that displays the date by using the shell command date. 14. Write a command line program that takes a number and a command as arguments. Call that command that number of times. For example, if your program name is "test" test 3 dir <shows directory> dir <shows directory> dir <shows directory>
UNIX Write and run a simple shell script name mymenu that creates a simple command menu. The script should present menu items (see below), prompts the user for a selection, and then executes the appropriate command selected. [Submit your script and the results of a test case for a, b, c, and d selections] COMMAND MENU a. Current date and time b. Name of the working directory c. Contents of the working directory Enter a, b, or c:
Unix questions, i need help on Hint: Commands to study to answer this question: predefined shell variables, and .profile script file, echo SHELL, HOME, PATH, MAIL and TERM are predefined shell variables. You can use the value of a shell variable in a shell command putting $ in front of it. For example, to display the value of the HOME directory of the user, specify $HOME in the echo command like echo $HOME. Do not give just the value of...
Write a Unix Shell Script to print all Armstrong Numbers between 1 and 1000. Your Program should include following key points: Program should have Header Comments. Program should print all Armstrong numbers between 1 and 1000: 1 153 370 371 407
Write a program in C or a script in bash, called “compare” that takes two numbers on the command line and compares them. The program should print the result of the comparison. Specifically, it should print “<x> is <comparison> <y>”, where <x> is the first number, <y> is the second number and <comparison> is one of “equal to”, “greater than” or “less than”. If the two numbers are equal, the program should have an exit status of zero. The exit...
Write a bash shell script, deleteFilesWithZeroLength.sh, that removes all zero length ordinary files in the directory passed as an optional argument. If you do not specify the directory argument, the script uses the present working directory as the default argument. Do appropriate exception handling in your script such as:If the arguments are more than 1, print out “Too many arguments passed”.If the argument passed is a regular file, print out “XXX is regular file”.1c. If the directory doesn’t exist, print out “Directory...
Hello all, I have a c++/unix (bash) question.
I am struggling on starting this assignment. If you could start the
assignment and tell me how to do the rest it would be greatly
appreciated!
(Quick thumbs up answer response if thorough and correct)
Maintain automobile records in a database Write a shell script to
create, view and modify a simple database that contains automobile
records. The shell script has to be done in Bourne shell syntax
(bash as a matter...