Chapter 5 Summary
By far the largest subject in this chapter is parameter expansion, and by far the largest section of parameter expansion is devoted to those expansions that were introduced by the KornShell and incorporated into the standard Unix shell. These are tools that give the POSIX shell much of its power. The examples given in this chapter are relatively simple; the full potential of parameter expansion will be shown as you develop serious programs later in the book.
Next in importance are arrays. Though not part of the POSIX standard, they add a great deal of functionality to the shell by making it possible to collect data in logical units.
Understanding the scope of variables can save a lot of head scratching, and well-named variables make a program more understandable and maintainable.
Manipulating the positional parameters is a minor but important aspect of shell programming, and the examples given in this chapter will be revisited and expanded upon later in the book.
Commands
declare: Declares variables and sets their attributes
eval: Expands arguments and executes the resulting command
export: Places variables into the environment so that they are available to child processes
shift: Deletes and renumbers positional parameters
shopt: Sets shell options
unset: Removes a variable entirely
Concepts
Environment: A collection of variables inherited from the calling program and passed to child processes
Array variables: Variables that contain more than one value and accessed using a subscript
Scalar variables: Variables that contain a single value
Associative arrays: Array variables whose subscript is a string rather than an integer