bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH] confusing/obsolete handling of test -t operator (and doc war


From: Chet Ramey
Subject: Re: [PATCH] confusing/obsolete handling of test -t operator (and doc warnings against using -o/-a)
Date: Fri, 7 Jul 2023 15:52:28 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0

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




reply via email to

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