• Arun Kumar

Shell Script to Simple Calculator

Linux shell script allows users to create a calculation to perform the calculation as they perform in the calculator. In order to achieve this, we will be using a case statement to perform the calculation as per the user input.


vi simple_calculator.sh
# !/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" 

Here is the sample output of the above script


More we to make a calculator

  • You can use else if to perform the calculation as per user input.

  • You can also use the While loop to perform the same operation.

170 views

Recent Posts

See All

Oracle 19c Installation on Linux

Oracle 19c adds more features to Oracle database and this article demonstrates Oracle 19c installation on Linux 7. We will be using Oracle Linux 7 and Oracle Database 19.3 softwares for this activity.

Basic Linux Commands

This article describes basic Linux commands that you must know as a system or database administrator. Below commands in Linux help you manage any Linux server fast and smoothly. Linux Command List Che

Linux Firewall with iptables and firewalld

In this article will be covering details regarding iptables and firewalld which helps in Linux firewall management. We will also be looking at how to enable specific ports (1521 for Oracle) inside ipt