On 12/14/20 4:45 AM, Oğuz wrote:

     $ Y+='($foo 3)'
     $ declare -p Y
     declare -A Y=([0]="(\$foo 3)" ["1 2"]="3" )

Where did the 0 come from?

That's a scalar assignment. You quoted the parens so it can't be a compound
assignment. Since the variable is an array, and an assignment was performed
without a subscript, you get the default subscript of "0".

The difference between this and quoting the rhs of an assignment when you
use `declare' is that `declare' is a builtin, and so its arguments undergo
a round of expansion before `declare' sees them. That's the fundamental
difference between assignment statements and arguments to declaration
commands that look like assignment statements.

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

Reply via email to