I'm using an array to try to subtraction. However, when my script just gives me the total of my array with a negative sign in front of it. Any suggestions?
elif [ "$OP" = "Subtraction" ]; then
echo "Please enter the number of values you would like to perform $OP"
read num
while [[ $num -gt $i ]]; do
echo "Enter your value"
read value
let total=$total-$value
let valuearr[$i]=$value
let i=$i+1
done
echo "You entered ${valuearr[*]}, and asked me to perform $OP. The answer is $total."
totalis unset, you will get a negative sum if you enter positive values.$totalstarts empty, so when you enter1,2, and3, your script computes0 - 1 - 2 - 3, which clearly is the same as-(1 + 2 + 3).$iwhen this script fragment is entered? What about$total?