Question: Unix Scripting: Write each of these scripts in Bourne Shell, C-Shell, Korn Shell, and Z-Shell. 1. Script that asks the user for a number and
Unix Scripting: Write each of these scripts in Bourne Shell, C-Shell, Korn Shell, and Z-Shell.
1. Script that asks the user for a number and prints out if it is even or odd.
2. Script that asks the user Are you OK?
If user replies y or Y, then say Glad to hear it else if the user enters n or N then print Sorry that you are not feeling good. If the user enters some other character, then print incorrect choice and ask the question again.
3. Write a script that asks the user for a score. If the score is between 90 and 100, then print You got an A, else if between 80 and 90, then You got a B and so on. If less than 60, then You failed. If the user enters number not between 0 and 100, then print the error message and exit the script.
Modify this script such that the user runs it with a number between 0 and 100 as an argument to the script and not ask the user for the score.
4. Write a script that saves the current date in a variable and then shifts through the different parts/elements of the date using a loop and prints each one out in a separate line.
5. Write a script that uses a switch or case statement (depending on shell) to do the following. First ask the user for a color. If they enter anything that begins with bl or Bl, then print the sky color is (whatever the user entered).
If the user enters red or yellow, the print the sun is sometimes this color. If the user enters any other color, then enter that the color is not in any of the categories defined.
6. Write a simple while loop which prints out numbers from 0 through 9 using the @ operator and a variable. In case of Bourne shell, use the expr command to increment the loop variable.
7. Write a script called days which is run as follows from the command line:
days Monday Tuesday Wednesday Thursday Friday Saturday Sunday
and it prints out the days in the following way:
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
Tuesday Wednesday Thursday Friday Saturday Sunday
Wednesday Thursday Friday Saturday Sunday
Thursday Friday Saturday Sunday
Friday Saturday Sunday
Saturday Sunday
Sunday
8. Write a script that takes in two arguments that are positive integers. The script should figure out which of the two integers is smaller and should use that to figure out the greatest common divisor (GCD) of the two integers and print it out. Also, figure out the lowest common multiple (LCM) of the two integers and print it out.
9. Write a function called in Bourne shell that uses the first argument/parameter to calculate the square of the integer the user enters when running the script. If the script is called swuare.sh, then the user will run it as follows from the prompt:
$ 5
% 25 //the result.
10. Write a script in both Bourne and C shell that presents a user with a menu as follows:
Add the numbers (enter a or A)
Subtract the numbers (enter s or S)
Multiply the numbers (enter m or M)
Divide the numbers (enter d or D)
Exit (select e or E)
If the user enters any other character other than the ones mentioned, then print an error saying it is not a choice and ask the user to select again until the correct option is chosen.
Once the operation is done, ask the user if they want to do another operation on the same two integers or do another operation with two different integers or exit. Do accordingly based on the users choice. So until the user does not select the exit option, the user is presented with a menu. Also, when you run the script, provide two integers as command line arguments. The beginning of your script should have an if statement that checks how many arguments are coming in and present a few statements about Usage of the script if the number of arguments is not 2.
11. Write a script in both Bourne and C shell that asks the user for an integer between 1 and 10 and prints out sum of integers from 1 through the number entered and also the product of the integers from 1 through the number entered (which is also called the factorial).
So for example, if the user enters 4, then the script should print the sum as 10 (1+2+3+4) and 24 (1*2*3*4).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
