From 5e91e0897661ef17b5e3eadd7b7a48c0f4c1adf7 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 28 Feb 2015 18:34:20 -0800 Subject: [PATCH] Created SC2154 (markdown) --- SC2154.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC2154.md diff --git a/SC2154.md b/SC2154.md new file mode 100644 index 0000000..9de4b3e --- /dev/null +++ b/SC2154.md @@ -0,0 +1,25 @@ +## var is referenced but apparently never assigned. + +### Problematic code: + + var=name + n=42 + echo "$var_$n.jpg" + +### Correct code: + + var=name + n=42 + echo "${var}_$n.jpg" + +### Rationale: + +ShellCheck has noticed that you reference a variable that is not assigned. Double check that the variable is indeed assigned, and that the name is not misspelled. + +Note: This message only triggers for variables with lowercase characters in their name (`foo` and `kFOO` but not `FOO`) due to the standard convention of using lowercase variable names for unexported, local variables. + +### Exceptions: + +ShellCheck does not attempt to figure out runtime or dynamic assignments like with `source mycommonvars.sh` or `eval var=value`. + +If you know for a fact that the variable is set, you can use `${var:?}` to fail if the variable is unset (or empty). You can also disable the message with a [[directive]]. \ No newline at end of file