I'm trying to write a script that will accept positional arguments (command-line arguments) that specify a mathematical operation (add, sub, mult, div, mod) and two values. The script is supposed to get this input, compute the result, and display the answer. I'm not sure where I went wrong because when I try to run my script, this is what I get
./trial.sh mod 15 10 ./trial.sh: 6: if [[ mod == add ]] then: not found Result: 25 ./trial.sh: 9: elif [[ mod == sub ]] then: not found Result: 5 ./trial.sh: 12: elif [[ mod == mult ]] then: not found Result: 150 ./trial.sh: 15: elif [[ mod == div ]] then: not found Result: 1 ./trial.sh: 18: elif [[ mod == mod ]] then: not found Result: 5 ./trial.sh: 21: else: not found error ./trial.sh: 23: fi: not found
This is the code I used that presented that result
#!/bin/bash
a=$1
b=$2
c=$3
result=0
" if [[ $a == add ]] then"
result=$((b + c))
echo "Result: " $result
" elif [[ $a == sub ]] then"
result=$((b - c))
echo "Result: " $result
" elif [[ $a == mult ]] then"
result=$((b * c))
echo "Result: " $result
" elif [[ $a == div ]] then"
result=$((b / c))
echo "Result: " $result
" elif [[ $a == mod ]] then"
result=$((b % c))
echo "Result: " $result
" else"
echo "error"
"fi"