you want to change $(($i++))
to ((i++))
. see https://askubuntu.com/questions/385528/how-to-increment-a-variable-in-bash
Let's deconstruct $(($i++))
. going outwards, $i
expands to 0. so we have the expression $((0++))
. 0 can't be incremented since it is a value, not a variable. so you get your error message line 26: 0++: syntax error: operand expected (error token is "+")
.
The reason to use ((i++))
without a $ at the front is that the $ at the front would actually evaluate i
. You don't want i
to be evaluated here, you just want i
to be incremented. (h/t the other guy)