[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to assign one associative array to another?
From: |
Peng Yu |
Subject: |
Re: How to assign one associative array to another? |
Date: |
Tue, 6 Apr 2021 11:28:28 -0500 |
For the purpose of loading the variable back to the shell, they are the same?
On Tue, Apr 6, 2021 at 11:07 AM Marco Ippolito <maroloccio@gmail.com> wrote:
>
> > What is the difference between `echo "${x[@]@A}"` and `declare -p x`.
> > Are they exact the same?
>
> The two are not the same, as a simple test would prove, e.g.:
>
> $ a=1; declare -p a; echo "${a@A}"
> declare -- a="1"
> a='1'
>
> The @A form of Parameter Transformation makes a determination as to which
> output format to employ based on the characteristics of the shell variable for
> which to perform the substitution.
>
> The output above shows the "bare" form and compares it with the "declare -p"
> form. It is more compact.
>
> When attributes are defined on the variable, a ``declare -<attributes>'' form
> is
> adopted instead, so that it may display said attributes, e.g.:
>
> # declare -i b=2; echo "${b@A}"
> declare -i b='2'
>
> Finally, if a variable has attributes associated with it but no value assigned
> to it, a third form omitting the equal (``='') sign is preferred:
>
> $ declare -r c; echo "${c@A}"
> declare -r c
>
> This machination is coded in the C source file for substitution logic and in
> all three forms leverages the ``name'' field of the ``SHELL_VAR`` struct, so
> it only varies in the part not pertaining to the value representation.
--
Regards,
Peng