• Arun Kumar

Shell Script to Perform Arithmetic Operations

Linux shell script allows users to do the arithmetic operation with user input for the operations. In order to achieve this, we will be using a case statement.


vi airth.sh
#!/bin/bash

echo "enter a and b"
read a
read b
echo "enter operation to be performed"
read op
case $op in
+) c=`expr $a + $b` ;;
-) c=`expr $a - $b` ;;
/) c=`expr $a / $b` ;;
\*) c=`expr $a \* $b` ;;
*) echo "no valid operation specified" ;;
esac
echo Result after performing operation on a and b is
echo $c

Here is the sample output of the above script


More ways to use this case statement.

  • You can use case to accept YES or NO, the same way software installation, during the license agreement.

  • You can also use to find File type from the Extension.

14 views

Recent Posts

See All

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

Passwordless SSH in Linux

Every time you ssh from one Linux server to another, you need to enter target server user's password. We can also setup passwordless ssh in Linux between two Linux servers so that you don't have to en