mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
give an explaination behind this shellcheck code.
23
SC2250.md
23
SC2250.md
@@ -1,3 +1,26 @@
|
||||
# Prefer putting braces around variable references even when not strictly required.
|
||||
|
||||
This error is optional and not enabled by default.
|
||||
|
||||
## Problematic code:
|
||||
|
||||
```shell
|
||||
partial_path='example'
|
||||
|
||||
curl "http://example.com/$partial_path_version/explain.html"
|
||||
```
|
||||
|
||||
## Correct code:
|
||||
|
||||
```shell
|
||||
partial_path='example'
|
||||
|
||||
curl "http://example.com/${partial_path}_version/explain.html"
|
||||
```
|
||||
|
||||
## Rationale:
|
||||
|
||||
If a variable gets called, and there is a string that gets appended to the variable that could get misinterpreted as possibly part of the name of the variable. Then it will not call the right variable.
|
||||
|
||||
## Related resources:
|
||||
- [StackOverflow: How do we separate variables from letters in shell scripting](https://stackoverflow.com/questions/18320133/how-do-we-separate-variables-from-letters-in-shell-scripting)
|
Reference in New Issue
Block a user