Program runs fine once I learned the correct format for giving it permission and the syntax for running it from command line. I am a forgetful beginner.
#!/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"
You have to add the execute flag to the file to execute it as ./BashCalculator.sh
.
chmod +x BashCalculator.sh
If you want to put it in $PATH
, either append the directory to it or place it in one of the paths of $PATH
.
EDIT:
Also, enclose your question with three backticks to format it properly. This way it's better to read. You must update your question if you have additional information. Do not place such information in a comment (just as @Poshi commented).
Please read this for more information about questions.