I just wondered what exactly the difference between
[[ $STRING != foo ]]
[ $STRING != foo ]
is, apart from that the latter is posix-compliant, found in sh and the former is an extension found in bash.
There are several differences. In my opinion, a few of the most important are:
For the most part, the rest is just some nicer syntax. To see more differences, I recommend this link to a FAQ answer: What is the difference between test, [ and [[ ?. In fact, if you are serious about bash scripting, I recommend reading the entire wiki, including the FAQ, Pitfalls, and Guide. The test section from the guide section explains these differences as well, and why the author(s) think
Keywords: Keywords are quite like builtins, but the main difference is that special parsing rules apply to them. For example, [ is a bash builtin, while [[ is a bash keyword. They are both used for testing stuff, but since [[ is a keyword rather than a builtin, it benefits from a few special parsing rules which make it a lot easier:
The first example returns an error because bash tries to redirect the file b to the command [ a ]. The second example actually does what you expect it to. The character < no longer has its special meaning of File Redirection operator.
Based on a quick reading of the relevant sections of the manpage, the primary difference appears to be that the