[Top][All Lists]

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

Re: [Help-bash] ${var:?message} customization

From: Eric Blake
Subject: Re: [Help-bash] ${var:?message} customization
Date: Thu, 14 May 2015 07:06:51 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 05/14/2015 06:23 AM, Greg Wooledge wrote:
> If you want to distinguish between "unset" and "set to an empty string",
> you can use a more subtle test:
> if [ "${var+defined}" ]; then

By the way, this test can be portably shortened to:

if [ ${var+y} ]; then

(one of the few places where unquoted variable expansion actually does
the right thing, even on ancient shells)

>     if [ -z "$var" ]; then

Conversely, while this is portable to POSIX shells, it is NOT portable
to some older implementations of /bin/sh (where there are certain values
of $var such as ")" that cause [ to misbehave).

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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