[Top][All Lists]

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

Re: in bash 4.4.12,want to verify a behavior...

From: Chet Ramey
Subject: Re: in bash 4.4.12,want to verify a behavior...
Date: Sun, 17 Feb 2019 21:54:19 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.0

On 2/15/19 11:45 PM, L A Walsh wrote:
> I printed the various declares using:
> declare -p |& more
> One of the early entries is:
> declare -A BASH_ALIASES=()
> Yet if I type 'alias |& wc, I see 56 lines starting with alias.
> I _thought_ BASH_ALIASES was suppose to hold the aliases
> and for an "alias whence='type -a'", I should see something like
> declare -A BASH_ALIASES=([whence]='type -a ...) instead of
> the empty assignment above.

Not quite. Dynamic variables are only defined to return the correct value
when they are referenced. The rest of the time, the values are
indeterminate (and possibly stale). The idea is that you can get an element
given the right index, or all the elements with the `*' or `@' subscripts.

Dynamic scalar variables generally hang onto the last value generated
and generate a new value when referenced.

Dynamic array variables fall into two classes: objects bash maintains
internally as arrays (BASH_ARGV, BASH_SOURCE, BASH_LINENO, FUNCNAME) and
arrays that reflect structures maintained by other commands (BASH_ALIASES,
BASH_CMDS, DIRSTACK, GROUPS). The latter group is generated on demand when
a subscript is referenced. For that group, the array doesn't have any
contents until you ask for something. After you do, of course, the values
show up in `declare' output.

`declare -p' just lists variables and any existing values. It doesn't cause
values to be generated. `declare -p BASH_ALIASES' counts as asking for the

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/

reply via email to

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