I am trying to escape the * character when running this calculator script, but when I run it, it does not output an error, but simply exits the script.
./calculator 3 * 4
should print Usage-./calculator.sh ....
, but instead it just exits. I am not allowed to use \* between the numbers. Tried everything possible according to me but I can't seem to make it work. Any help would be appreciated.
Also, I'm ssh'ing to my school server from my Macbook, would that be an issue?
#!/bin/bash -f
if [ "$#" == "0" ] || [ "$2" == '*' ]
then
echo Usage-./calculator.sh value1 operator value2
echo where,
echo value1: numeric value
echo value2: numeric value
echo operator: one of +,-,/,x
elif [ "$2" == "+" ]
then
echo $(( $1 + $3 ))
elif [ "$2" == "-" ]
then
echo $(( $1 - $3 ))
elif [ "$2" == "x" ]
then
echo $(( $1 * $3 ))