Tuesday, August 8, 2023

.::: Linux Unix Shell Script : Create Store Procedure Simple Calculator :::.

 1. create Simple_Calculator.sh
[root@teguhth data]# cat Simple_Calculator.sh
#!/bin/bash

echo "Simple Calculator"
echo "Enter first number:"
read num1

echo "Enter second number:"
read num2

echo "Enter operator (+, -, *, /):"
read operator

case $operator in
    +) result=$(($num1 + $num2));;
    -) result=$(($num1 - $num2));;
    \*) result=$(($num1 * $num2));;
    /) result=$(($num1 / $num2));;
    *) echo "Invalid operator"; exit 1;;
esac

echo "Result: $result"

[root@teguhth data]#

    +) result=$(($num1 + $num2));;
    -) result=$(($num1 - $num2));;
    \*) result=$(($num1 * $num2));;
    /) result=$(($num1 / $num2));;
    *) echo "Invalid operator"; exit 1;;
esac

echo "Result: $result"


2. run

sh Simple_Calculator.sh

[root@teguhth data]# sh Simple_Calculator.sh
Simple Calculator
Enter first number:
200
Enter second number:
40
Enter operator (+, -, *, /):
+
Result: 240
[root@teguhth data]# sh Simple_Calculator.sh
Simple Calculator
Enter first number:
200
Enter second number:
40
Enter operator (+, -, *, /):
-
Result: 160
[root@teguhth data]# sh Simple_Calculator.sh
Simple Calculator
Enter first number:
100
Enter second number:
400
Enter operator (+, -, *, /):
-
Result: -300
[root@teguhth data]# sh Simple_Calculator.sh
Simple Calculator
Enter first number:
100
Enter second number:
400
Enter operator (+, -, *, /):
*
Result: 40000
[root@teguhth data]#


3. capture result 

 

No comments:

Post a Comment

Popular Posts