Incorrect Equality Operator Medium

Script incorrectly uses == operator. For variable assignment, use single =. For equality comparison, use = or == within test brackets.

Detector ID
shell/incorrect-equality-operator@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-
Tags
-

Noncompliant example

1
2# Noncompliant: Incorrect assignment using `==`.
3count==0
4while [ $count -lt 5 ]; do
5    echo $count
6    count=$((count + 1))
7done

Compliant example

1
2# Compliant: Proper assignment using single `=`.
3count=0
4while [ $count -lt 5 ]; do
5    echo $count
6    count=$((count + 1))
7done