[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: No expansions performed while declaring an associative array using a
From: |
Chet Ramey |
Subject: |
Re: No expansions performed while declaring an associative array using a list of keys and values |
Date: |
Mon, 14 Dec 2020 09:24:47 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 |
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 chet@case.edu http://tiswww.cwru.edu/~chet/
- Re: No expansions performed while declaring an associative array using a list of keys and values, (continued)
Re: No expansions performed while declaring an associative array using a list of keys and values, Chet Ramey, 2020/12/11
Re: No expansions performed while declaring an associative array using a list of keys and values, felix, 2020/12/14