From d5b9529ecd81f87f0398c71bded562b5a0bc667b Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 4 May 2019 13:12:55 -0700 Subject: [PATCH] Created SC2171 (markdown) --- SC2171.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 SC2171.md diff --git a/SC2171.md b/SC2171.md new file mode 100644 index 0000000..ed88bd9 --- /dev/null +++ b/SC2171.md @@ -0,0 +1,41 @@ +## Found trailing ] outside test. Add missing [ or quote if intentional. + +### Problematic code: + +```sh +if foo -eq bar ]; then true; fi +``` + +or + +```sh +tr -d ] +``` + +### Correct code: + +```sh +if [ foo -eq bar ]; then true; fi +``` + +or + +```sh +tr -d ']' +``` + +### Rationale: + +ShellCheck found a non-test command that ends with `]` or `]]`. + +If this was intended to be a test expression like in the first example, add the missing `[` or `[[`. + +If the `]` was intended to be literal, like in `tr -d ]`, you can quote to make this obvious. + +### Exceptions: + +`tr -d ]` is valid and not different from `tr -d ']'`, so in these cases you can ignore the error instead. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file