Last Updated: September 09, 2019
·
992
· rrader

C-style loops in bash

Just found out it's possible to use C-style loops in bash, for example:

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

General form:

for (( expr1 ; expr2 ; expr3 )) ; do list ; done

It's extremely useful, and this feature works on bash>=2.04, so it has to work on most environments.

more info: http://www.softpanorama.org/Scripting/Shellorama/Control_structures/loops.shtml#C_style_for_loop