Skip to content
Grische edited this page Nov 11, 2021 · 2 revisions

Prefer [[ ]] over [ ] for tests in Bash/Ksh.

This is an optional suggestion. It must be explicitly enabled with a directive enable=require-double-brackets in a # shellcheck comment or .shellcheckrc

Problematic code:

[ -e /etc/issue ] 

Correct code:

[[ -e /etc/issue ]]

Rationale:

ShellCheck has been explicitly asked to warn about uses of [ .. ] in favor of the extended Bash/Ksh test [[ .. ]].

[[ .. ]] suppresses word splitting and globbing, supports a wider variety of tests, and is generally safer and better defined than [ .. ]. For an in-depth list of differences, see the Related Resources.

Exceptions:

This check is not enabled by default, and may have been turned on for your current project by someone who wants it enforced. You can still ignore it with a directive.

This suggestion does not trigger for Sh or Dash scripts, even when explicitly enabled, as these shells don't support [[ .. ]].

Related resources:

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