Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 27
    The empty string (and many other) problem is solved by using quotes. The "x" is to cover another kind of problems: where operands may be taken as operators. Like when $foo is ! or ( or -n... That problem is not meant to be a problem with POSIX shells where the number of arguments (beside [ and ]) is not greater than four. Commented Jan 25, 2013 at 20:36
  • 38
    To clarify, [ x$foo = x$blah ] is just as plain wrong as [ $foo = $bar ]. [ "$foo" = "$bar" ] is correct in any POSIX compliant shell, [ "x$foo" = "x$bar" ] would work in any Bourne-like shell, but the x is not for cases where you have empty strings but where $foo may be ! or -n... Commented Mar 7, 2013 at 16:29
  • 11
    Interesting semantics in this answer. I'm not sure what you mean by it's *not* syntax. Of course, [ isn't precisely an alias for test. If it were, then test would accept a closing square bracket. test -n foo ]. But test does not, and [ requires one. [ is identical to test in all other respects, but that's not how alias works. Bash describes [ and test as shell builtins, but [[ as a shell keyword. Commented Oct 9, 2017 at 13:02
  • 10
    Well, in bash [ is a shell builtin, but /usr/bin/[ is also an executable. It is traditionally a link to /usr/bin/test, but in modern gnu coreutils is a separate binary. The traditional version of test examines argv[0] to see if it is invoked as [ and then looks for the matching ]. Commented Jan 9, 2019 at 20:03
  • 1
    My bash does not work with >= and <= Commented Jul 22, 2019 at 13:15