On 7/11/24 9:42 AM, Dr. Werner Fink wrote:
Hi,I've a report that with later bash the following which works in bash-4.2 x () { local x=y declare -p x echo $x unset x declare -p x echo $x } with linux-40cm:~ # x () { > local x=y > declare -p x > echo $x > unset x > declare -p x > echo $x > } linux-40cm:~ # x declare -- x="y" y -bash: declare: x: not foundbut with bash-5.X the reporter sees (and complains)sl15sp5:~ # x () { > local x=y > declare -p x > echo $x > unset x > declare -p x > echo $x > } sl15sp5:~ # x declare -- x="y" y declare -- x
The variable is unset: it has attributes (local) but has not been assigned a value. The idea behind preserving the local attribute is that the variable will continue to be reported as unset while in the function, but assigning it a new value will preserve it as a local variable. This is how bash has behaved since 1995 (bash-2.0). The bug in bash-4.2 was that it didn't tell you which instance of a variable the shell would modify if it were subsequently assigned a value. The local variable still exists, is unset, and would be used by expansions and assignments, but `declare' would not tell you that. This would have been clearer to see (and more misleading) if the variable x also had a value at the global scope. A discussion that prompted the change starts at https://lists.gnu.org/archive/html/bug-bash/2013-11/msg00000.html Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature