Exactly
EXCELLENT !
THANKS
On 8/29/23, Lawrence Velázquez <vq@larryv.me> wrote:
> On Mon, Aug 28, 2023, at 1:34 PM, Budi wrote:
>> What is variable in condition such
>>
>> [[ ${foo-} = bar ]]
>>
>> as seen in a Linux script of its main package
>>
>> why is it if just
>> [[ $foo = bar ]]
>>
>> Please give useful info
>
> The former accommodates foo being unset in a script using set -u,
> and the latter doesn't.
>
> % bash -uc 'unset foo; [[ ${foo-} = bar ]]; echo "$?"'
> 1
> % bash -uc 'unset foo; [[ $foo = bar ]]; echo "$?"'
> bash: line 1: foo: unbound variable
>
> So the script in question uses set -u, or the author was programming
> defensively, or the author saw the idiom somewhere and adopted it
> without understanding its purpose.
>
> --
> vq
>