From b6c9a4f2f5ffdf9a364b00058ad094cbd9f86220 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 16 Apr 2017 18:36:34 -0700 Subject: [PATCH] Created SC2212 (markdown) --- SC2212.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 SC2212.md diff --git a/SC2212.md b/SC2212.md new file mode 100644 index 0000000..891a33b --- /dev/null +++ b/SC2212.md @@ -0,0 +1,28 @@ +## Use 'false' instead of empty [/[[ conditionals. + +### Problematic code: + +```sh +if [ ] +then + echo "Temporarily disabled" +fi +``` + +### Correct code: + +```sh +if false +then + echo "Temporarily disabled" +fi +``` +### Rationale: + +`[ ]` is a somewhat obscure way of expressing falsehood, and the behavior is likely intended to allow the incorrectly quoted command `[ $var ]` to still work when the variable is unset. + +POSIX has a more descriptive command `false` for this. + +### Exceptions: + +None. This is a stylistic suggestion, and has no effect on how the script works. \ No newline at end of file