Date: Fri, 25 Nov 2022 16:53:11 -0500 From: Greg Wooledge <g...@wooledge.org> Message-ID: <y4e5r6fcwdqa9...@wooledge.org>
| 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). A positional param, rather than a special param, but the same argument applies. | So, there's no reason to expect that "test -v 1" would work. And even with variables, is non portable, and as alternatives exist here which are portable and just as easy to use, why not just use one of thise, such as: | you should use something like: | test "$#" -gt 0 but only for positional params (the 0 is 1 less than the positional param to be checked ... for positional params, if one exists (is set), all those before it are also set. This can be easier to read if written as 'test "$@" -ge 1' which means the same. My preferred method for this, which works for all kinds of variables and parameters is test "${X+s}" = s where X is whatever is to be tested (1 in this case) and "s" is any string you like, except "" .. must be the same both occurrences of course. kre