[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Some Special Array Variables Only Kind Of Initialized
From: |
John R. Graham |
Subject: |
Some Special Array Variables Only Kind Of Initialized |
Date: |
Fri, 10 Jan 2014 18:06:45 -0500 (GMT-05:00) |
Some of the automagically created special array variables (GROUPS and DIRSTACK
for soer; perhaps others) appear to not be fully initialized. Their values
don't appear correctly in some corner cases until they've been referenced with
parameter expansion (I think that's the triggering criteria, anyway). The
following shell dialog illustrates:
~ $ # Start a new shell.
~ $ bash
~ $ bash --version | head -n1
GNU bash, version 4.2.45(1)-release (i686-pc-linux-gnu)
~ $ # Look at some array variables with 'set'.
~ $ set | grep 'GROUPS\|DIRSTACK'
DIRSTACK=()
GROUPS=()
~ $ # Hmm. Empty? Really?
~ $ echo ${GROUPS[@]}
1000 11 14 18 19 20 27 35 80 85 100 250 995 996 10 1003 1013
~ $ echo ${DIRSTACK[@]}
~
~ $ # Okay, not empty.
~ $ # Look at 'em again with set.
~ $ set | grep 'GROUPS\|DIRSTACK'
DIRSTACK=([0]="~")
GROUPS=([0]="1000" [1]="11" [2]="14" [3]="18" [4]="19" [5]="20" [6]="27"
[7]="35" [8]="80" [9]="85" [10]="100" [11]="250" [12]="995" [13]="996"
[14]="10" [15]="1003" [16]="1013")
~ $ # Hmm again. Now shown correctly.
~ $ exit
exit
So far the Bash source code is a somewhat abstruse to me so I thought I'd ask
for a little help.
Thanks in advance.
- John
- Some Special Array Variables Only Kind Of Initialized,
John R. Graham <=