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/dont-mask-return-values.md. A documentation index is available at /llms.txt.

Do not mask command exit status in export assignments

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

Metadata

ID: bash-code-quality/dont-mask-return-values

Language: Bash

Severity: Warning

Category: Best Practices

Description

Combining export with command substitution on one line hides the exit status of the command. The assignment runs a command, but the overall status comes from export, which usually succeeds. Assign first, then export: foo="$(mycmd)" and then export foo. Literal values such as export foo=bar do not have this problem.

Non-Compliant Code Examples

#!/bin/bash
export foo="$(false)"
export BAR=$(date)
export FOO bar=$(cmd)

Compliant Code Examples

#!/bin/bash
foo="$(false)"
export foo

x=$(date)
export x

export PLAIN=literal

bar=$(cmd)
export FOO bar
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