SC3005 – ShellCheck Wiki

See this page on GitHub

Sitemap


In POSIX sh, arithmetic for loops are undefined.

Problematic code:

for ((i=0; i<10; i++))
do 
  echo "$i"
done

Correct code:

i=0
while [ "$i" -lt 10 ]
do 
  echo "$i"
  i=$((i+1))
done

Rationale:

C-style arithmetic for loops are a Ksh/Bash feature that's not supported by POSIX sh or dash. Use a while loop with separate initialization and incrementing instead.

Exceptions:

None


ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.