Answer the question
In order to leave comments, you need to log in
Why does it give an "invalid arithmetic" error?
#!/bin/bash
read r
for ((i=0; i<$r; i++))
do
read l w h
s=$((2*$h*$(($w+$l))))
if (($s%16!=0))
then
echo $(($s/16+1)) | bc -l
else
echo $(($s/16)) | bc -l
fi
done
STDIN:
2
2 4 7
1 2 3
Errors:
main.sh: line 3: ((: i<2
: syntax error: invalid arithmetic operator (error token is "
")
Answer the question
In order to leave comments, you need to log in
Because $r must be a number, and yours is a string with a digit and a newline.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question