On Fri, Nov 25, 2022 at 03:40:42PM -0600, G. Branden Robinson wrote:
> 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.

[...]

It's a bash extension, not part of POSIX.  From 'help test':

      -v VAR         True if the shell variable VAR is set.

Or from the man page:

       -v varname
              True if the shell variable varname is set (has been  assigned  a
              value).

So the question is whether "1" qualifies as a "shell variable".  I would
argue that it doesn't -- it's a special parameter, not a variable (because
you can't assign to it).

So, there's no reason to expect that "test -v 1" would work.  If you want
to test whether there's at least one argument, you should use something
like:

(($# > 0))     # bash extension

or

test "$#" -gt 0

Reply via email to