Ce produit n'est pas pris en charge par le site Datadog que vous avez sélectionné. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: bash-code-quality/ambiguous-argument-concatenation

Language: Bash

Severity: Warning

Category: Code Style

Description

Putting literal text and a list expansion ($@ or ${name[@]}) inside the same double-quoted word is ambiguous: Bash concatenates the literal with only the first and last expanded words in a surprising way, so the resulting argv is hard to predict and easy to get wrong.

Prefer separate arguments, use $* when a single string is acceptable, or quote only the literal so the list expansion stands alone.

Non-Compliant Code Examples

#!/bin/bash
printf '%s\n' "Bad parameters: $@"
msg="$@tail"
echo "x ${v[@]}"
echo "${arr[@]}suffix"

Compliant Code Examples

#!/bin/bash
printf '%s\n' "$@"
printf '%s\n' "${files[@]}"
printf '%s\n' "Bad parameters: $*"
printf '%s\n' "Bad parameters: " "$@"
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains