You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test mis-parse with compound expression involving string comparison where LHS is a flag known to test #5947
test takes a number of flags, such as test -g filename, but it prioritizes binary operators over interpreting an argument as a flag, e.g. test -g = -g is parsed as a string comparison. This is useful when the first arg is actually a variable, e.g. test "$flag" = -g.
Unfortunately, this fails once a compound expression is involved. test -g = -g -o -g = --graph (which comes from test "$flag" = -g -o "$flag" = --graph). In this case it instead parses the -g as the unary operator and emits the error
test: Expected a combining operator like '-a' at index 2
This is true even when using parentheses to group, e.g. test \( -g = -g \) -o \( -g = --graph \).
Reproduced with recent master (fish, version 3.0.2-1297-gb41e5cbbb-dirty) as well as version 3.0.2.
Looks like this has been filed before as #5186, but that issue was closed saying this is just an edge case. Closing that was wrong; bash is able to parse this correctly.
Note that this isn't actually even a violation of POSIX, because:
>4 arguments:
The results are unspecified.
To be perfectly frank, test sucks, and should be replaced. And the replacement should not have combining operators, and most of all should not include a one argument mode.
If anyone cares enough to write a patch for this, we'll merge it.
Activity
lilyball commentedon Jun 19, 2019
Looks like this has been filed before as #5186, but that issue was closed saying this is just an edge case. Closing that was wrong; bash is able to parse this correctly.
faho commentedon Jun 21, 2019
Note that this isn't actually even a violation of POSIX, because:
To be perfectly frank, test sucks, and should be replaced. And the replacement should not have combining operators, and most of all should not include a one argument mode.
If anyone cares enough to write a patch for this, we'll merge it.
faho commentedon Jul 2, 2019
Okay, I'm gonna close this as a duplicate of #1337. @lilyball even commented essentially the same example.