mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC1037 (markdown)
21
SC1037.md
Normal file
21
SC1037.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
## Without braces, this is $1 plus a literal. Use ${10} instead.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
echo "Ninth parameter: $9"
|
||||||
|
echo "Tenth parameter: $10"
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
echo "Ninth parameter: $9"
|
||||||
|
echo "Tenth parameter: ${10}"
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
For legacy reasons, `$10` is interpreted as the variable `$1` followed by the literal string `0`.
|
||||||
|
|
||||||
|
Curly braces are needed to tell the shell that both digits are part of the parameter expansion.
|
||||||
|
|
||||||
|
### Contraindications
|
||||||
|
|
||||||
|
If you wanted the trailing digits to be literal, `${1}0` will make this clear to both humans and shellcheck.
|
Reference in New Issue
Block a user