Skip to content
Joachim Ansorg edited this page Nov 12, 2021 · 2 revisions

Found trailing ] outside test. Add missing [ or quote if intentional.

Problematic code:

if foo -eq bar ]; then true; fi

or

tr -d ]

Correct code:

if [ foo -eq bar ]; then true; fi

or

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!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally