Hi Alex, At 2022-11-25T22:02:46+0100, Alejandro Colomar wrote: > I wrote a script, and am trying it on many systems. On RHEL8, which > has bash 4, it didn't work. I could reduce the problem to the > following command, which never returns true: > > test -v 1; > > In Debian Sid, where I develop, and where I have bash 5, that works > fine, and is true if the function or script in which it is has any > arguments. On zsh(1) it also works fine. > > Is this a known bug in bash? > The exact version where I can reproduce it is 4.4.20(1)-release > (x86_64-redhat-linux-gnu).
I don't think it is a bug. It is unspecified behavior according to POSIX. "-v" is not an operator according to POSIX, and I don't recall seeing it in any shell. It is therefore interpreted as a string argument. The algorithm for determining the precedence of the operators and the return value that shall be generated is based on the number of arguments presented to test. (However, when using the "[...]" form, the right-bracket final argument shall not be counted in this algorithm.) In the following list, $1, $2, $3, and $4 represent the arguments presented to test: 0 arguments: Exit false (1). 1 argument: Exit true (0) if $1 is not null; otherwise, exit false. 2 arguments: If $1 is '!', exit true if $2 is null, false if $2 is not null. If $1 is a unary primary, exit true if the unary test is true, false if the unary test is false. Otherwise, produce unspecified results. https://pubs.opengroup.org/onlinepubs/009695299/utilities/test.html Regards, Branden
signature.asc
Description: PGP signature