bug-bash
[Top][All Lists]
Advanced

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

New array_expand_once option


From: Chet Ramey
Subject: New array_expand_once option
Date: Tue, 13 Jun 2023 16:20:33 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0

The latest push to the devel branch extends the assoc_expand_once
semantics to indexed array variables. This means that a construct
like

export subscript='$(uname >&2 ; echo 0)'
shopt -s assoc_expand_once
printf -v a["$subscript"] %s hi
declare -p a

will no longer run `uname' and assign "hi" to subscript 0. This affects
shell builtins that take array references as arguments, which undergo one
round of word expansion before the builtin performs the assignment.

The affected builtins are primarily

printf
read
wait

since those assign values to variable names passed as arguments.

The option also affects

declare
let
local
typeset
test
[
unset

For example, the following does not run `uname':

export subscript='$(uname >&2 ; echo 0)'
shopt -s assoc_expand_once
let a["$subscript"]+=1

To better describe its functionality, I renamed assoc_expand_once to
array_expand_once. The old name is still accepted.

When the next version of bash is released, the old bash-5.2 behavior (that
runs `uname' in the above examples) will be available if the shell
compatibility level is set to 52 or lower.

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/



reply via email to

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