On 7/6/23 2:29 AM, Stephane Chazelas wrote:
Hello,

Thanks for the report.


test -t X

Always returns false and doesn't report an error about that
invalid number (beside the point here, but in ksh/zsh, that X is treated
as an arithmetic expression and evaluates to 0 if $X is not set).

Yes, this should report an error about expecting an integer.


While:

test -t X -a Y

returns a "too many arguments" error.

Same.


test X -a -t -a Y

returns false (without error and regardless of whether any fd is a tty)

Historical versions of test made the argument to -t optional here. I can
continue to support that in default mode for backwards compatibility, but
it will be an error in posix mode.


while

test X -a Y -a -t

returns true

Yes, at the end of the arguments, this is the same as a one-argument test,
just like `test -t' doesn't check fd 1.


While for other unary operators that gives:

$ bash -c 'test X -a -x -a Y'
bash: line 1: test: too many arguments

Yep, the other unary operators don't have optional arguments.


I also noticed that the fact that -a/-o were deprecated (by POSIX at
least) and made for unreliable test expressions was not noted in the
manual. So I suggest the patch below:

I added some language about this, noting that POSIX has deprecated them
and recommending scripts not use them. Thanks for the suggestion.

Chet

--
``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/


Reply via email to