Skip to content
Vidar Holen edited this page Oct 20, 2022 · 1 revision

Escaping \< is required in [..], but invalid in [[..]]

Problematic code:

[[ aardvark \< zebra ]]

Correct code:

[[ aardvark < zebra ]]

Rationale:

Grammatically speaking, [ is considered a normal command name, so < and > are interpreted as redirections. When using the lexicographical string operators < and > in [ .. ], they must be escaped (e.g. \< or "<").

[[ is considered its own grammatical construct, and therefore it does not require (nor does it allow) escaping < or >.

Exceptions:

None

Related resources:

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!

ShellCheck

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

Clone this wiki locally