From 35ca8bb92316454bad5ed43232dab59d7baf181d Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 12 Feb 2014 18:45:39 -0800 Subject: [PATCH] Created SC1007 (markdown) --- SC1007.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 SC1007.md diff --git a/SC1007.md b/SC1007.md new file mode 100644 index 0000000..a45a971 --- /dev/null +++ b/SC1007.md @@ -0,0 +1,28 @@ +# Remove space after = if trying to assign a value (or for empty string, use var='' ... ). + +### Problematic code: + + # I want programs to show text in dutch! + LANGUAGE= nl + + # I want to run the nl command with English error messages! + LANGUAGE= nl + +### Correct code: + + # I want programs to show text in dutch! + LANGUAGE=nl + + # I want to run the nl command with English error messages! + LANGUAGE='' nl + +### Rationale: + +It's easy to think that `LANGUAGE= nl` would assign `"nl"` to the variable `LANGUAGE`. It doesn't. + +Instead, it runs `nl` (the "number lines" command) and sets `LANGUAGE` to an empty string in its environment. + +Since trying to assign values this way is a common mistake, ShellCheck warns about it and asks you to be explicit when assigning empty strings (except for `IFS`, due to the common `IFS= read ..` idiom). + +### Contraindications +If you're familiar with this behavior and feel that the explicit version is unnecessary, you can ignore the message. ``alias shellcheck=`shellcheck -e SC1007` `` \ No newline at end of file