For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/bash-code-quality/deprecated-bracket-arithmetic.md. A documentation index is available at /llms.txt.

Avoid deprecated $[expr] arithmetic expansion syntax

This product is not supported for your selected Datadog site. ().

Metadata

ID: bash-code-quality/deprecated-bracket-arithmetic

Language: Bash

Severity: Warning

Category: Code Style

Description

The $[expression] form is an old Bash arithmetic expansion. It was never documented in POSIX, and Bash 5.2 removed support for it without a clear parse error in all cases, so scripts can fail silently on newer systems.

Use the standard $((expression)) form instead, which is widely supported and portable.

Non-Compliant Code Examples

#!/bin/bash
echo "$[1 + 1]"
y=$[2 * 3]

Compliant Code Examples

#!/bin/bash
echo "$((1 + 1))"
x=$((a * 2))
y=$(( (3 + 4) ))
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security