From a868c2faec5708aa3d3e35404e2cb57292550647 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 13 Nov 2019 22:01:41 -0800 Subject: [PATCH] Created SC2256 (markdown) --- SC2256.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SC2256.md diff --git a/SC2256.md b/SC2256.md new file mode 100644 index 0000000..12ed868 --- /dev/null +++ b/SC2256.md @@ -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! \ No newline at end of file