bug-bash
[Top][All Lists]
Advanced

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

Re: Undocumented behaviour - parameter expansion ${par-word}


From: Eric Blake
Subject: Re: Undocumented behaviour - parameter expansion ${par-word}
Date: Tue, 04 Sep 2012 05:18:49 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0

On 09/04/2012 05:13 AM, Roman Rakus wrote:
> Hi,
> Petr, adding to cc: list, found behaviour not documented, neither in man
> page nor bash ref manual:
> ${par-word} will do expansion of par, and if the par is unset it is
> substituted by word. It is different from ${par:-word}, where word is
> used when par is unset or null.
> 
> Is it undocumented and deprecated, like $[]? Or just undocumented?

It is fully documented, and required by POSIX.  Read two lines above:

       When  not  performing  substring  expansion, using the forms
documented
       below, bash tests for a parameter that is unset or null.
Omitting  the
       colon results in a test only for a parameter that is unset.

       ${parameter:-word}
              Use  Default  Values.  If parameter is unset or null, the
expan‐
              sion of word is substituted.  Otherwise, the value of
parameter
              is substituted.


It's a shame that the form ${parameter-word} is not called out more
directly in a form easy to search for, and that you have to read in two
places to piece things together yourself; but it IS supported and
documented.

-- 
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]