|
From: | Chet Ramey |
Subject: | Re: ${a:=b} expands to `b', not `a''s value |
Date: | Wed, 20 Jan 2021 10:44:36 -0500 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 |
On 1/20/21 6:16 AM, Oğuz wrote:
$ 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 areconverted to lower-case. `:=`:If parameter is unset or null, the expansion of word is assigned toparameter. The value of parameter is then substituted. Is this a bug or am I missing something here?
Thanks for the report. It's probably not what you intend, but it's the way bash has done things all the way back to bash-4.0 when the additional variable attributes were introduced (and further back if you consider the integer attribute). The way bash does it is that the word is expanded (to `X') and that value is assigned to a. That becomes the value of the expansion. The conversion is then performed, at a lower layer, on the assignment. This should only affect this particular parameter expansion involving variables where this kind of conversion takes place at assignment time. I think it would be reasonable to change the result to the final value of the variable for the next version and make the new behavior dependent on the shell compatibility level. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
[Prev in Thread] | Current Thread | [Next in Thread] |