What is the purpose of the do keyword in Bash for loop syntax? To me, it feels redundant.for i in `seq 1 2`; do echo hi; doneWhy isn't the syntax like this?for i in `seq 1 2`; echo hi; doneI'm sure that it does fill a purpose. I just want to learn.
What is the purpose of the do keyword in Bash for loops?
bash;shell;for
Note that that syntax is inherited from the Bourne shell.After the variable name, you can have either in to have the list of elements explicitly given, or do, to loop over the positional parameters.for i in 1 2 3do  echo $idoneOrset 1 2 3for i do  echo $idoneHaving the do in both cases (even if it's not strictly  necessary in the first one) makes for a more consistent syntax. It's also consistent with the while/until loops where the do is necessary.while  cmd1  cmd2do  cmd3  cmd4doneYou need the do to tell where the list of condition commands end.Note that the Bourne shell did not support for i; do. That syntax was also not POSIX until the 2016 edition of the standard (for i do has always been POSIX; see the related Austin group bug).zsh has a few shorthand forms like:for i in 1 2 3; echo $ifor i (1 2 3) echo $ifor ((i=1;i<=3;i++)) echo $iOr support for more than one variable:for i j (1 a 2 b) echo $i $j(though you can't use in or do as variable name in place of j above).Even if rarely documented, most Bourne-like shells (Bourne, ksh, bash, zsh, not ash nor yash) also support:for i in 1 2 3; { echo $i;}The Bourne shell, ksh and zsh (but not bash) also support:for i { echo $i; }While bash, ksh and zsh (but not the Bourne shell) support:for i; { echo $i; }All (Bourne, bash, ksh, zsh) support:for i{ echo $i;}ksh93, bash, zsh support:for ((i=1;i<=3;i++)) { echo $i; }