mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2256 (markdown)
29
SC2256.md
Normal file
29
SC2256.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
## This translated string is the name of a variable. Flip leading $ and " if this should be a quoted substitution.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
var="foo"
|
||||||
|
echo $"var"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
var="foo"
|
||||||
|
echo "$var"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
`$".."` is a localized string, for example, `echo $"Hello $USER"` along with the proper translation files can be used to have the script say "Bonjour, youruser" in French locales.
|
||||||
|
|
||||||
|
In this case, ShellCheck found a localized string whose contents is also the name of a variable. This could have happened because the user wanted a far more common quoted substitution, e.g. `"$var"`, but accidentally switched the leading `$` and `"`.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
If you do want a localized string whose contents is also an active variable, you can [[ignore]] this warning or rename the variable.
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user