[Top][All Lists]

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

Re: [bash 4] 'test -v 1' is never true

From: Greg Wooledge
Subject: Re: [bash 4] 'test -v 1' is never true
Date: Fri, 25 Nov 2022 22:48:08 -0500

On Sat, Nov 26, 2022 at 10:09:22AM +0700, Robert Elz wrote:
> 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.

This is also recommended on <https://mywiki.wooledge.org/BashFAQ/083>
for the general case.

I don't personally suggest using it to check how many positional
parameters were given, because there are alternatives that are much
easier to read for that case.

reply via email to

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