I'm making a script for a class that should be asking you to enter two whole numbers and then ask you to select a / s / m / d for add, subtract multiply or divide. It will also make sure you entered a whole number and a valid option but I'll work on that later. For now here is what I have:
#!/bin/bash
echo "Please input a whole number"
read num1
echo "Please input another whole number"
read num2
echo "Please input funtion: [a] for addition, [s] for subtraction, [m] for multiply, or [d] for divide"
read func
if [ "$func" -eq "a" ]; then
echo $((num1 + num2))
fi
if [ "$func" -eq "s" ]; then
echo $((num1 - num2))
fi
if [ "$func" -eq "m" ]; then
echo $((num1 * num2))
fi
if [ "$func" -eq "d" ]; then
echo $((num1 / num2))
fi
else
echo "Please select only [a] for addtion, [s] for subtration, [m] for multiply, or [d] for divide"
When I run it, it asks for the things correctly but I'm getting errors I'm not understanding:
./MathTest.sh: line 9: [: a: integer expression expected
./MathTest.sh: line 13: [: a: integer expression expected
./MathTest.sh: line 17: [: a: integer expression expected
./MathTest.sh: line 21: [: a: integer expression expected
./MathTest.sh: line 25: syntax error near unexpected token `else'
./MathTest.sh: line 25: `else'
Would anyone give me a hand with this please?