On 4/14/24 5:16 AM, Emanuel Attila Czirai wrote:

Bash Version: 5.2
Patch Level: 26
Release Status: release

Description:
     the [ test with -n or -z on a string that's only the angle bracket char
followed by -a or -o operators, fails like:
bash: [: syntax error: `-n' unexpected

Repeat-By:

$ [ -n ">" -a -n "something" ] || echo hmm
bash: [: syntax error: `-n' unexpected
hmm

I think the part your analysis is missing is that `<' and `>' are binary
operators, so this really is an ambiguous expression.

POSIX test specifies what happens when there are four or fewer arguments
(and the upcoming issue 8 will remove -a/-o/(/) altogether); when you
have more than four you're dealing with historical algorithms. Historical
parsing gave the string comparison binary operators higher precedence than
the unary operators.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to