The script is as follows:
Code:
#!/bin/bash
#The script below came from:
#http://stackoverflow.com/questions/14350556/creating-a-calculator-script
PS3="what's the operation? "
declare -A op=([add]='+' [subtract]='-' [multiply]='*' [divide]='/')
while true; do
read -p "what's the first number? " n1
read -p "what's the second number? " n2
select ans in "${!op[@]}"; do
for key in "${!op[@]}"; do
[[ $REPLY == $key ]] && ans=$REPLY
[[ $ans == $key ]] && break 2
done
echo "invalid response"
done
formula="$n1 ${op[$ans]} $n2"
printf "%s = %s\n\n" "$formula" "$(bc -l <<< "$formula")"
done
In the past, I have been able to introduce a conditional (testing for
x as input) that exits the script and returns to prompt. Since downloading the above from the page mentioned in line 3 about four weeks ago, that didn't work so I removed it.
I'd like to write an "if/then" back in that
will work.
Carver