Question

In: Computer Science

Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter...

Using Bash script,

1. Print the multiplication table upto 10 rows. Ask the user to enter a number. say user enters 10, your output should be :

[srivatss@athena shell]> ./mult.sh
I will be printing the multiplication table
Please enter a number
10
1 x 10 = 10
2 x 10 = 20
3 x 10 = 30
4 x 10 = 40
5 x 10 = 50

6 x 10 = 60
7 x 10 = 70
8 x 10 = 80
9 x 10 = 90
10 x 10 = 100

[ 5 points ]

2. Create a Simple Calculator [ 20 points , 5 points for each operator]

Ask the user for the first operand, second operand and the operator. You output the result to the user based on the operator. Here is the sample output

[srivatss@athena shell]> ./calc.sh
Welcome to my Simple calculator
Please enter the first operand
2
Please enter the second operand
3
Please enter the operator
+
2 + 3 = 5


[srivatss@athena shell]> ./calc.sh
Welcome to my calculator
Please enter the first operand
4
Please enter the second operand
2
Please enter the operator
-
4 - 2 = 2
[srivatss@athena shell]> ./calc.sh
Welcome to my calculator
Please enter the first operand
4
Please enter the second operand
5
Please enter the operator
*
4 * 5 = 20
[srivatss@athena shell]> ./calc.sh
Welcome to my calculator
Please enter the first operand
6
Please enter the second operand
3
Please enter the operator
/
6 / 3 = 2

3. Using RANDOM function and touch command , create a file with prefix =BatchJob followed by the random number.  

For instance, I ran my script, it created a file with random number 10598.  

[srivatss@athena shell]> ./cmds.sh
BatchJob10598

[ 5 points ]

Solutions

Expert Solution

If you have any doubts, please give me comment...

mult.sh

echo "I will be printing the multiplication table"

echo "Please enter a number"

read n

i=1

while [ $i -le $n ]

do

    res=`expr $i \* $n`

    echo "$i x $n = $res"

    i=`expr $i + 1`

done

2)

echo "Welcome to my calculator"

echo "Please enter the first operand"

read n1

echo "Please enter the second operand"

read n2

echo "Please enter the operator"

read op

case "$op" in

    '+')

        result=`expr $n1 + $n2`

        echo "$n1 + $n2 = $result"

        ;;

    '-')

        result=`expr $n1 - $n2`

        echo "$n1 - $n2 = $result"

        ;;

    '*')

        result=`expr $n1 \* $n2`

        echo "$n1 * $n2 = $result"

        ;;

    '/')

        result=`expr $n1 / $n2`

        echo "$n1 / $n2 = $result"

        ;;

    *)

        echo "Invalid operator"

esac

3)

#!/bin/bash

RANDOM=$$

echo "BatchJob$RANDOM"


Related Solutions

Write the following program in Java. Ask the user to enter the number of rows and...
Write the following program in Java. Ask the user to enter the number of rows and columns for a 2-D array. Create the array and fill it with random integers using (int)(Math.random() * 20) (or whatever number you choose). Then, provide the user with several menu choices. 1. See the entire array. 2. See a specific row. 3. See a specific column. 4. See a specific value. 5. Calculate the average of each row. 6. Calculate the total of each...
5) Write a JavaScript script that will ask the user to enter in the length of...
5) Write a JavaScript script that will ask the user to enter in the length of the side of a cube. (all the sides of a cube are equal) Based on the value that is entered by the user from the keyboard, calculate each of the following and assign your results to variables. 1. volume of the cube 2. surface area of the cube 3. volume of the largest sphere that could fit in the box. 4. surface area of...
In Kali Linux Write a script that ask the user to enter an IP address and...
In Kali Linux Write a script that ask the user to enter an IP address and a port number, then use the provided entries from the user to perform a query on your local network and determine if the given port is open on the provide network. Need to submit solutions for both below. 1.A short report showing the functionality of your code 2. your bash script
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask...
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask the user to input the number of kilometers they need to travel. - Display the number of equivalent miles for the number. Use formula, Kilometers = miles/0.62137 - Every time the loop runs, it should ask the user if they want to continue, if user enters “Y” or “y”, then the loop runs again, if user enters “N” or “n”, then stop the loop...
Write a C++ script to perform the following: a.) Ask a user to enter 2 real...
Write a C++ script to perform the following: a.) Ask a user to enter 2 real numbers. b.) Save the user response as a variable a and b. c.) Display if the numbers are even or odd. d.) Check if the number a belongs in the interval D = [10, 99], display the output as "a is between 10 and 99" or "a is not between 10 and 99". e.) Check if the number b belongs in the interval E...
Ask the user to enter test scores. Once they have entered -1, print out the highest...
Ask the user to enter test scores. Once they have entered -1, print out the highest grade. Ensure that the grade entered is an integer.(Using Java Language) Enter integers between 0 and 100, -1 when finished. Enter a test score: [asdf] Enter an integer. Enter a test score: [32.5] Enter an integer. Enter a test score: [42] Enter a test score: [99] Enter a test score: [87] Enter a test score: [x] Enter an integer. Enter a test score: [-1]...
Write a bash script that... create new user ./finalProject user if a new user is to...
Write a bash script that... create new user ./finalProject user if a new user is to be created ask for the new users information and use it when creating the new user add a new printer ./finalProject printer ask anything you need in order to create the new printer (I.e. name) permissions ./finalProject permissions ask what document and permissions the user wants restarting the computer ./finalProject restart
Name the script while.sh. Ask the user to enter a positive integer. You can assume that...
Name the script while.sh. Ask the user to enter a positive integer. You can assume that the user will enter a positive integer (input validation for a positive number not required). Use a while loop to print all integers from 0 up to and including the integer entered. Each integer should be printed on a line by itself and nothing else should print. This is for Linux. I have not done anything on this script. Please help with simplistic commands...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n'...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n' (nxn chart).
Using Python write a program that does the following in order: 1. Ask user to enter...
Using Python write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT