bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax error with lone > or < as string in [ ] tests with -a or -o o


From: Chet Ramey
Subject: Re: syntax error with lone > or < as string in [ ] tests with -a or -o operators
Date: Mon, 15 Apr 2024 09:08:14 -0400
User-agent: Mozilla Thunderbird

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    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]