Unsupported Decimal Comparison Medium

Bash does not support decimal numbers in arithmetic comparisons. Either convert values to integers or use external tools like 'bc' or 'awk' for decimal calculations and comparisons.

Detector ID
shell/unsupported-decimal-comparison@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-
Tags
-

Noncompliant example

1
2# Noncompliant: Using test command with decimal numbers.
3if [ 0.5 -eq 0.50 ]; then
4    echo "The numbers are equal"
5fi

Compliant example

1
2# Compliant: Using `bc` to compare decimal numbers.
3if [[ $(echo "0.5 == 0.50" | bc -l) -eq 1 ]]; then
4    echo "The numbers are equal"
5fi