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...
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 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).
Write a short bash script that takes in two arguments from a user, asks the user...
Write a short bash script that takes in two arguments from a user, asks the user whether they would like to add, subtract, multiply, or divide. Each of these operations must be a function that returns data.
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...
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
C++ Have the user type in 10 numbers. Then, using STL STACKs print a table showing...
C++ Have the user type in 10 numbers. Then, using STL STACKs print a table showing each number followed by the next large number. For example, if the user types the following 7 5 12 25 The output should be this: Element Next Greater Number 5 --> 7 7 --> 12 12 --> 25 25 --> -1 You can use this functor to sort the vector: #include<iostream> #include<vector> #include<algorithm> using namespace std; struct greater { template<class T> bool operator()(T const...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT