help-bash
[Top][All Lists]
Advanced

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

Re: Variable in condtion such [[ ${v-} = 9 ]]


From: Budi
Subject: Re: Variable in condtion such [[ ${v-} = 9 ]]
Date: Tue, 29 Aug 2023 03:50:44 +0700

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
>



reply via email to

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