Missing Do Keyword Medium

A shell script contains a loop structure lacking the required do keyword, causing syntax error. To mitigate this, add do after the loop condition and before the loop commands.

Detector ID
shell/missing-do-keyword@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-
Tags
-

Noncompliant example

1
2# Noncompliant: Missing `do` keyword in the while loop.
3while [ $count -lt 10 ]
4  echo $count
5  count=$((count + 1))
6done

Compliant example

1
2# Compliant: `do` keyword properly included in the while loop.
3while [ $count -lt 10 ]
4do
5  echo $count
6  count=$((count + 1))
7done