3 ms·
"test" and its alias "[" are actually builtins: https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html https://www.gnu.org/software/bash
by js2 6y ago
"test" and its alias "[" are actually builtins:
https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html https://www.gnu.org/software/bash/manual/html_node/Bourne-Sh...
They also exist as executables for ancient backwards compatibility.
"[[" is a so-called "conditional construct":
https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html#Conditional-Constructs https://www.gnu.org/software/bash/manual/html_node/Condition...
I have a somewhat quirky style and almost always use "if test ..." since I find it clearer than "[" and usually don't need the additional functionality that "[[" provides.
- hagg3n 6y agoI honestly thought I was the only one, how cool is that? I too find `test` preferable over `[` since it leaves no doubt we're calling a command just like any other and the same assumptions still apply. I also avoid `[[` since it isn't posix and won't work in simpler shells.
- tpoacher 6y agosame
- waterhouse 6y agoI always use "test" and never "[" (and I've only used "[[" once when I thought I needed a builtin regex matcher for efficiency). Partly because fish does the same, partly because despite writing bash scripts for years I do not want to have the "[ vs [[" information in my brain (nor should whoever reads my code). (For similar reasons, whenever I'm grepping for a nontrivial regex, I always use egrep rather than grep, because the escaping semantics are simpler—"if it's escaped with a \, then it's not special"—and again I do not want to have the information of "which characters are special only when escaped in base grep" in my brain.)
- boogies 6y ago> I do not want to have the information of "which characters are special only when escaped in base grep" in my brain Tangential but relevant to the Edit thread today were vis was mentioned, “No more {very-,}{no,}magic modes with different semantics and escaping rules. Instead we use the familiar and predictable POSIX Extended Regular Expression variant.”¹ is a real advantage over vim. ¹https://github.com/martanne/vis/wiki/Differences-from-Vi(m)#posix-extended-regular-expressions-instead-of-a-custom-non-standard-variation https://github.com/martanne/vis/wiki/Differences-from-Vi(m)#...