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
本文章重点介绍了参数扩展和数组在Shell编程中的重要性和使用方法。详细探讨了由Korn Shell引入并被纳入标准Unix shell的参数扩展特性,这些特性赋予了POSIX shell强大的功能。同时,虽然数组不是POSIX标准的一部分,但它们极大地增强了shell的功能,使其能够以逻辑单位收集数据。此外,文章还讨论了变量作用域的理解如何避免许多常见错误,并强调了合理命名变量的重要性。

被折叠的 条评论
为什么被折叠?



