mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-03-12 12:35:25 -07:00
Quote POSIX
parent
58b975bab4
commit
eaff9f3b52
11
SC2166.md
11
SC2166.md
@ -18,7 +18,16 @@ And likewise, prefer `[ p ] || [ q ]` over `[ p -o q ]`.
|
||||
|
||||
### Rationale:
|
||||
|
||||
`-a` and `-o` to mean AND and OR in a `[ .. ]` test expression is not well defined. They are obsolescent extensions in [POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html) and the lack of additional quoting levels means that expressions involving these operators are often ambiguous. Values that begin with hyphens and the `!` string are the usual issues.
|
||||
`-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):
|
||||
|
||||
>The XSI extensions specifying the -a and -o binary primaries and the '(' and ')' operators have been marked obsolescent. (Many expressions using them are ambiguously defined by the grammar depending on the specific expressions being evaluated.) Scripts using these expressions should be converted to the forms given below. Even though many implementations will continue to support these obsolescent forms, scripts should be extremely careful when dealing with user-supplied input that could be confused with these and other primaries and operators. Unless the application developer knows all the cases that produce input to the script, invocations like:
|
||||
>
|
||||
> `test "$1" -a "$2"`
|
||||
>
|
||||
>should be written as:
|
||||
>
|
||||
> `test "$1" && test "$2"`
|
||||
|
||||
|
||||
Using multiple `[ .. ]` expressions with shell AND/OR operators `&&` and `||` is well defined and therefore preferred (but note that they have equal precedence, while `-a`/`-o` is unspecified but usually implemented as `-a` having higher precedence).
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user