From 64dda4c618bcd8d62688d0f7196fbc2e4c60d203 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 18 Jul 2015 11:31:47 -0700 Subject: [PATCH] Created SC2159 (markdown) --- SC2159.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC2159.md diff --git a/SC2159.md b/SC2159.md new file mode 100644 index 0000000..da26dd7 --- /dev/null +++ b/SC2159.md @@ -0,0 +1,25 @@ +## [ 0 ] is true. Use 'false' instead + +### Problematic code: + + if [ 0 ] + then + echo "always triggers" + fi + +### Correct code: + + if false + then + echo "never triggers" + fi + +### Rationale: + +`[ str ]` checks whether `str` is non-empty. It doesn't matter if `str` is `0`, it will still be evaluated for non-emptyness. + +Instead, use the command `false` which -- as the manual puts it -- does nothing, unsuccessfully. + +### Exceptions: + +None \ No newline at end of file