help-bash
[Top][All Lists]
Advanced

[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 09:34:00 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 05/14/2015 09:17 AM, Stephane Chazelas wrote:

>>> if [ "${var+defined}" ]; then
>>
>> By the way, this test can be portably shortened to:
>>
>> if [ ${var+y} ]; then
> 
> That assumes $IFS doesn't contain y. If it does, then depending
> on the shell, if $var is set, that's:
> 

> It does not in those cases and there's no reason why you
> wouldn't quote it. Not-quoting it is still asking the shell to
> split+glob it.

Unless you are changing IFS, splitting won't happen (portable scripts
really don't set IFS to include 'y'); and globbing won't change the
answer.  Yes, avoiding split+glob is a good practice, but my point
remains that it is portable _in this instance_ to drop quoting for the
result of a smaller script (and autoconf does just that).

> 
> test "${var+y}" 
> 
> would be portable.

Yes, it is also portable, but not as short.

> Using case here would be a way to avoid quoting if you don't
> like quotes:
> 
> case ${var+y} in
>   y) echo set
> esac

Also not as short.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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