Updated 2018-08-12 06:33:36 by pooryorick

array names retrieves the names of keys in an array.

Synopsis  edit

array names arrayName ?mode? ?pattern?

Description  edit

Returns a list containing the names of all of the variables in the array that match pattern. Mode may be one of -exact, -glob, or -regexp. If specified, mode designates which matching rules to use to match pattern against the names of the variables in the array. If not specified, mode defaults to -glob. See the documentation for string match for information on glob style matching, and the documentation for regexp for information on regexp matching. If pattern is omitted then the command returns the names of all of variables in the array. An empty string is returned if there are no (matching) variables in the array or if arrayName isn't the name of an array variable,

To obtain the keys in alphabetical order:
foreach key [lsort [array names arr]] {...}