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