Timeline for Why does parameter expansion with spaces without quotes work inside double brackets "[[" but not inside single brackets "["?
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 3, 2021 at 7:03 | comment | added | Nate T | @kojiro Agreed, and regardless the test command is syntax as well. Aside from literals, (and I know I'll somehow regret stating this part) It is all bash syntax OP if you read this, maybe change to 'operator'? Sry to nit-pick, I know it was likely a figure of speech, but the Q/A is fairly popular now, and many in the linux realm get their start with coding via Ubuntu /Bash or similar, so this may be an introduction to the term for some. | |
| S Oct 22, 2020 at 12:05 | history | edited | AdminBee | CC BY-SA 4.0 |
Rephrase to avoid misunderstandings
|
| Oct 22, 2020 at 9:17 | review | Suggested edits | |||
| S Oct 22, 2020 at 12:05 | |||||
| Jul 22, 2019 at 13:15 | comment | added | Student |
My bash does not work with >= and <=
|
|
| Jan 9, 2019 at 20:03 | comment | added | Evan | 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 ]. | |
| Oct 9, 2017 at 13:02 | comment | added | kojiro |
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.
|
|
| Mar 7, 2013 at 16:29 | comment | added | Stéphane Chazelas |
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...
|
|
| Jan 25, 2013 at 20:36 | comment | added | Stéphane Chazelas |
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.
|
|
| Feb 20, 2012 at 19:25 | vote | accept | Majid Azimi | ||
| Feb 20, 2012 at 18:42 | history | answered | SiegeX | CC BY-SA 3.0 |