help-bash
[Top][All Lists]
Advanced

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

Re: ${param+x} ?


From: Tapani Tarvainen
Subject: Re: ${param+x} ?
Date: Tue, 19 Dec 2023 13:36:22 +0200

On Tue, Dec 19, 2023 at 11:38:50AM +0100, lacsaP Patatetom 
(patatetom@gmail.com) wrote:

> this form `${param+x}` is not documented (man) but is accepted by bash and
> differs from `${param:+x}`

It is documented on the man page:

"When not performing substring expansion, using the forms documented
below (e.g., :‐), bash tests for a parameter that is unset or null.
**Omitting the colon results in a test only for a parameter that is
unset.**"

> it is found in a script in this test :
> [ -z ${param+x} ]
> 
> what's the point of this test, which will always be true ?

That is true only if param is unset:

tt@saukko:~$ param=a
tt@saukko:~$ if [ -z ${param+x} ] ; then echo true; else echo false ;fi
false
tt@saukko:~$ param=
tt@saukko:~$ if [ -z ${param+x} ] ; then echo true; else echo false ;fi
false
tt@saukko:~$ unset param
tt@saukko:~$ if [ -z ${param+x} ] ; then echo true; else echo false ;fi
true

-- 
Tapani Tarvainen



reply via email to

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