bug-bash
[Top][All Lists]
Advanced

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

Re: ${a:=b} expands to `b', not `a''s value


From: Oğuz
Subject: Re: ${a:=b} expands to `b', not `a''s value
Date: Wed, 20 Jan 2021 15:01:56 +0200

20 Ocak 2021 Çarşamba tarihinde Léa Gris <lea.gris@noiraude.net> yazdı:

> Le 20/01/2021 à 12:16, Oğuz écrivait :
>
>>      $ declare -l a
>>      $ echo "${a:=X} $a"
>>      X x
>>
>> This doesn't jive with what the manual says.
>>
>> `-l`:
>>
>>> When the variable is assigned a value, all upper-case characters are
>>>
>> converted to lower-case.
>>
>> `:=`:
>>
>>> If parameter is unset or null, the expansion of word is assigned to
>>>
>> parameter.
>>
>
> The assignation part:
> a is assigned X but it is stored as x in a.
>
> The value of parameter is then substituted.
>>
>
> The expansion part:
> The value X is expanded but is not affected by the lowercase
> transformation flag from a, so it remains as X.
>

The manual makes it explicit that it is `a''s value that is substituted,
not the value assigned to it, i.e X. I'd expect `${a:=X}' to expand to a
lowercase x there.

I filed a similar report here:
https://github.com/ksh93/ksh/issues/157


> The fact that an expansion also assign a value is a questionable design
> choice though.
>
> If I had to use this I would just silence the expansion as an argument to
> the dummy true or : command
>
> : ${a:=X}
>
> Is this a bug or am I missing something here?
>>
>
> Then likely not.
>
>
> --
> Léa Gris
>
>
>

-- 
Oğuz


reply via email to

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