A
A
Andrey2019-03-03 18:18:17
bash
Andrey, 2019-03-03 18:18:17

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

1 answer(s)
V
Vitsliputsli, 2019-03-03
@Vitsliputsli

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 question

Ask a Question

731 491 924 answers to any question