Arithmetic Expansion Modernization Medium

The square bracket syntax for arithmetic expansion is deprecated in Bash and can lead to compatibility issues. The '$((..))' syntax offers a more consistent and recommended way to perform calculations within your shell script.

Detector ID
shell/arithmetic-expansion-modernization@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-
Tags
-

Noncompliant example

1
2# Noncompliant: Uses the deprecated `$[..]` syntax.
3x=5
4y=3
5result=$[x * y]
6echo "Result: $result"

Compliant example

1
2# Compliant: Use the standard `$((..))` syntax for arithmetic operations.
3x=5
4y=3
5result=$((x * y))
6echo "Result: $result"