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: Léa Gris
Subject: Re: ${a:=b} expands to `b', not `a''s value
Date: Wed, 20 Jan 2021 13:47:27 +0100
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

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




reply via email to

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