mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2297 (markdown)
29
SC2297.md
Normal file
29
SC2297.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
## Double quotes must be outside ${}: ${"invalid"} vs "${valid}".
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
echo ${"USER"}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
echo "${USER}"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
ShellCheck found a parameter expansion containing what appears to be a quoted variable name.
|
||||||
|
|
||||||
|
While the parameter expansion itself must be quoted, as in `"${valid}"`, the quotes may not appear inside the `{}` as in `${"invalid"}`.
|
||||||
|
|
||||||
|
Also note that translated strings like `$"Hello"` may not use curly braces.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user