help-bash
[Top][All Lists]
Advanced

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

Re: ${param+x} ?


From: Greg Wooledge
Subject: Re: ${param+x} ?
Date: Tue, 19 Dec 2023 07:18:27 -0500

On Tue, Dec 19, 2023 at 12:12:46PM +0100, lacsaP Patatetom wrote:
> so, what's the point of this test `[ -z ${param+x} ]`, which will always be
> true ?

That expansion is incorrect.  What you *want* is [ -n "${param+x}" ]
or simply [ "${param+x}" ].

If 'param' is unset, "${param+x}" expands to the empty string, and
you get [ -n "" ] which is false.

If 'param' is set to any value, including the empty string, "${param+x}"
expands to x, and you get [ -n x ] which is true.

See also <https://mywiki.wooledge.org/BashFAQ/083>.



reply via email to

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