Increment a counter in POSIX sh
Increment a counter in POSIX sh with i=$((i + 1)). The i++ and let forms are Bash and ksh extensions that dash reports as command not found.
A loop counter in a #!/bin/sh script is built with arithmetic expansion, because the shorter forms from Bash are not portable.
i=0
i=$((i + 1))
i=$((i + 1))
echo "i is $i"
i++
let i=i+1
(( i++ ))i is 2
main.sh: 5: i++: not found
main.sh: 6: let: not found
main.sh: 7: i++: not found$((expression)) is arithmetic expansion, defined in POSIX, and it works in every conforming shell. The three failed lines at the end show what Debian's dash does with the other forms: it looks for a command named i++ or let, and it reads (( as two nested subshells.
Arithmetic expansion is signed integer only, and inside it variables need no dollar sign. The postfix increment inside it, as in $((i++)), is not guaranteed by POSIX, so keep the assignment form.