help-bash
[Top][All Lists]
Advanced

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

Re: How to assign one associative array to another?


From: Marco Ippolito
Subject: Re: How to assign one associative array to another?
Date: Tue, 6 Apr 2021 13:07:30 -0300

> 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.



reply via email to

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