Question

In: Computer Science

Write a script that represents a simple command line calculator. It will accept two numbers from...

Write a script that represents a simple command line calculator. It will accept two numbers from command line, and then display sum, difference and product of these two numbers. Provide script code and screenshot of output.

Using Linux Ubuntu bash

Solutions

Expert Solution

CODE

# !/bin/bash

# Take user Input
echo "Enter Two numbers : "
read a
read b

# Input type of operation
echo "Enter Choice :"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
read ch

# Switch Case to perform
# calulator operations
case $ch in
1)res=`echo $a + $b | bc`
;;
2)res=`echo $a - $b | bc`
;;
3)res=`echo $a \* $b | bc`
;;
4)res=`echo "scale=2; $a / $b" | bc`
;;
esac
echo "Result : $res"

OUTPUT

​​​​​​​


Related Solutions

UNIX ONLY Write a bash script that will accept a filename as a command line argument....
UNIX ONLY Write a bash script that will accept a filename as a command line argument. Your script should first check whether the filename has been passed as argument or not (hint: at least one argument has to be provided). If no argument has been provided your script should display appropriate message and exit. If a file name has been provided, your script should check if the file exists in the current directory and display the contents of the file....
Write a script named countmatches that expects at least two arguments on the command line. The...
Write a script named countmatches that expects at least two arguments on the command line. The first argument is the pathname of a dna file containing a valid DNA string with no newline characters or white space characters of any kind within it. (It will be terminated with a newline character.) This dna file contains nothing but a sequence of the bases a, c, g, and t in any order. The remaining arguments are strings containing only the bases a,...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
write an awk script that works as wc command.
write an awk script that works as wc command.
Using MatLab Write a program which will: a. Accept two numbers from the user m and...
Using MatLab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Accept from the user two row numbers. Multiply the two rows (element by element) and find the sum. Print the result. d. Accept from the user two column numbers. Add the two columns (element by element) and find the sum....
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For example, java Adder 3 2.5 -4.1 should print The sum is 1.4
in C programing language Two numbers entered from the command line (example: calculate.exe 2 + 2)...
in C programing language Two numbers entered from the command line (example: calculate.exe 2 + 2) Add, subtract, divide and multiply by (+, -, /, *) operators Write the C program that makes the calculation using switch-case. hint: operator [2][0] comes from index .
Write a decision-making program with command-line interface to implement a housing-score calculator (inspired by the 2020...
Write a decision-making program with command-line interface to implement a housing-score calculator (inspired by the 2020 Nifty Decision Makers by Evan Peck) Your program will consist of two functions: main() Asks the user 5 questions and stores the answers: year (int), age (int), probation (string), full-time (int), gpa (float) (see sample run below) Calls computeScore(answers), where answers is a list containing the variables in which the answers are stored in the order in which they are received (python lists may...
Please write program in C++ format: Write a program to accept five negative numbers from the...
Please write program in C++ format: Write a program to accept five negative numbers from the user. (1) Find the average of the five numbers and display the answer to the standard output. Keep the answer two decimal points - 5 points (2) Output the numbers in ascending order and display the answer to the standard output. - 5 points
**Need to use awk command in putty (should be a ONE LINE COMMAND) Write the command...
**Need to use awk command in putty (should be a ONE LINE COMMAND) Write the command that would find all lines that have an email address and place a label email = before the line in the file longfile output will multiple lines similar to this one : using a good awk command the output would be something like this email = From: "Linder, Jann/WDC" <[email protected]> email = To: Mr Arlington Hewes <[email protected]> email = > From: Mr Arlington Hewes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT