[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Docco
From: |
Andreas Schwab |
Subject: |
Re: Docco |
Date: |
Wed, 27 Mar 2024 12:40:02 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
On Mär 27 2024, Greg Wooledge wrote:
>> $ [ ! -a /tmp ] && echo ok || echo nok
>> ok
>
> Here, you have three arguments, and argument 2 is a "binary primary"
> (POSIX wording again), so it's treated as if you had written this:
>
> [ ! ] && [ /tmp ] && echo ok || echo nok
>
> This is simply performing two string length tests. Both strings are
> non-empty (the first is one character, and the second is four), so
> the result is true.
>
> The check for whether the first argument is '!' is not performed,
> because the "$2 is a binary primary" check comes first. This is how
> POSIX documents it.
FWIW, ksh parses it the other way round:
$ ksh93 -c '[ ! -a /tmp ]; echo $?; [ . -a /tmp ]; echo $?; [ - -a /tmp ]; echo
$?'
1
0
ksh93: [: -: unknown operator
2
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
- Docco, Phi Debian, 2024/03/27
- Re: Docco, Andreas Kähäri, 2024/03/27
- Re: Docco, Greg Wooledge, 2024/03/27
- Re: Docco,
Andreas Schwab <=
- Re: Docco, Chet Ramey, 2024/03/27