9.23.1. Using the Stored Lists
Let's start with a quick overview of expanding array
values; then we'll look at specifics for each shell.
A dollar sign ($) before the name of a shell
variable gives you its value. In the C shells and
zsh, that gives all members of an array. But, in
the Korn shell and bash2, expanding an array
value without the index gives just the first member. To pick out a
particular member, put its number in square brackets after the name;
in ksh and bash2, you also
need to use curly braces ({}). A hash mark
(#) gives the number of members. Finally, you can
use range operators to choose several members of an array.
Here's a practical example that you might use,
interactively, at a shell prompt. You're cleaning
your home directory tree. You store all the directory names in an
array named d. When you've
cleaned one directory, you go to the next one. This way, you
don't miss any directories. (To keep this simple,
I'll show an example with just four directories.)