Text-only Table of Contents (frame/ no frame)
(27) Arrays Previous Top Next

Variable arrays

Both ksh and bash implement arrays of variables, but in somewhat different ways.

ksh distinguishes between numerically indexed (small) arrays, and string indexed (associative) arrays. bash uses integers for all array indexing, but the integers need not be consecutive and unassigned array elements do not exist. Arrays must be declared before use, e,g. typeset -A myarray (ksh associative array), or typeset -a myarray (bash).

Array elements are set with the syntax: myarray[index]=value and referenced with the syntax ${myarray[index]}

This example shows use of an array indexed by IP addresses, as strings in ksh or as non-consecutive numbers in bash. It also demonstrates use of getopt for options processing

Example: getauthlogs display, text


Previous Top Next


arrays.src  last modified Mar 22, 2012 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College