Updated SC2166 (markdown)

Mingye Wang
2021-04-12 19:16:33 +08:00
parent 54e9cbed14
commit 798cdbda54

@@ -15,7 +15,6 @@ And likewise, prefer `[ p ] || [ q ]` over `[ p -o q ]`.
``` ```
### Rationale: ### Rationale:
`-a` and `-o` to mean AND and OR in a `[ .. ]` test expression is not well defined, and can cause incorrect results when arguments start with dashes or contain `!`. [From POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html): `-a` and `-o` to mean AND and OR in a `[ .. ]` test expression is not well defined, and can cause incorrect results when arguments start with dashes or contain `!`. [From POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html):
@@ -34,3 +33,6 @@ Using multiple `[ .. ]` expressions with shell AND/OR operators `&&` and `||` is
### Exceptions: ### Exceptions:
If the shell variant being used is ksh derived (such as the bash shell) it will have the shell builtin command `[[ ... ]]`. This has the operators `&&`, `||`, `(`, `)`, `!` which safely avoid the ambiguity by noting which arguments were quoted and requiring the operators to be unquoted (except by the `[[ ... ]]` construct itself). If the shell variant being used is ksh derived (such as the bash shell) it will have the shell builtin command `[[ ... ]]`. This has the operators `&&`, `||`, `(`, `)`, `!` which safely avoid the ambiguity by noting which arguments were quoted and requiring the operators to be unquoted (except by the `[[ ... ]]` construct itself).
### See also:
* [Problems With the test Builtin: What Does -a Mean?](http://www.oilshell.org/blog/2017/08/31.html)