Skip to main content

Shell Scripting: Expert Recipes for Linux, Bash, and more

Shell Scripting: Expert Recipes for Linux, Bash, and more

Steve Parker

ISBN: 978-1-118-16632-1

Aug 2011

600 pages

$32.99

Description

A compendium of shell scripting recipes that can immediately be used, adjusted, and applied

The shell is the primary way of communicating with the Unix and Linux systems, providing a direct way to program by automating simple-to-intermediate tasks. With this book, Linux expert Steve Parker shares a collection of shell scripting recipes that can be used as is or easily modified for a variety of environments or situations. The book covers shell programming, with a focus on Linux and the Bash shell; it provides credible, real-world relevance, as well as providing the flexible tools to get started immediately.

  • Shares a collection of helpful shell scripting recipes that can immediately be used for various of real-world challenges
  • Features recipes for system tools, shell features, and systems administration
  • Provides a host of plug and play recipes for to immediately apply and easily modify so the wheel doesn't have to be reinvented with each challenge faced

Come out of your shell and dive into this collection of tried and tested shell scripting recipes that you can start using right away!

INTRODUCTION xxix

PART I: ABOUT THE INGREDIENTS.

CHAPTER 1: THE HISTORY OF UNIX, GNU, AND LINUX 3

CHAPTER 2: GETTING STARTED 15

CHAPTER 3: VARIABLES 33

CHAPTER 4: WILDCARD EXPANSION 67

CHAPTER 5: CONDITIONAL EXECUTION 83

CHAPTER 6: FLOW CONTROL USING LOOPS 111

CHAPTER 7: VARIABLES CONTINUED 139

CHAPTER 8: FUNCTIONS AND LIBRARIES 161

CHAPTER 9: ARRAYS 199

CHAPTER 10: PROCESSES 219

CHAPTER 11: CHOOSING AND USING SHELLS 255

PART II: RECIPES FOR USING AND EXTENDING SYSTEM TOOLS.

CHAPTER 12: FILE MANIPULATION 279

CHAPTER 13: TEXT MANIPULATION 315

CHAPTER 14: TOOLS FOR SYSTEMS ADMINISTRATION 353

PART III: RECIPES FOR SYSTEMS ADMINISTRATION.

CHAPTER 15: SHELL FEATURES 409

CHAPTER 16: SYSTEMS ADMINISTRATION 427

CHAPTER 17: PRESENTATION 459

CHAPTER 18: DATA STORAGE AND RETRIEVAL 471

CHAPTER 19: NUMBERS 483

CHAPTER 20: PROCESSES 501

CHAPTER 21: INTERNATIONALIZATION 517

PART IV: REFERENCE.

APPENDIX: FURTHER READING 529

GLOSSARY 533

INDEX 539

ReadMe
Download
Code Download :: Chapter 2
Download
Code Download :: Chapter 5
Download
Code Download :: Chapter 6
Download
Code Download :: Chapter 7
Download
Code Download :: Chapter 8
Download
Code Download :: Chapter 9
Download
Code Download :: Chapter 10
Download
Code Download :: Chapter 12
Download
Code Download :: Chapter 13
Updated on 2/13/17
Download
Code Download :: Chapter 14
Download
Code Download :: Chapter 15
Download
Code Download :: Chapter 16
Download
Code Download :: Chapter 17
Download
Code Download :: Chapter 18
Download
Code Download :: Chapter 19
Download
Code Download :: Chapter 20
Download
Code Download :: Chapter 21
Download
ChapterPageDetailsDatePrint Run
16Author's update: The "Shellshock" bug in GNU's Bash shell
To read the article on the author's website, visit
http://steve-parker.org/articles/shellshock/
10/8/14

244Text Correction
Currently Reads:
$ while read ip name alias
should read:
$ while read ip name aliases
10/02/14

73Error in Text
2nd paragraph, last sentence:

CURRENTLY SAYS:
"This is expressed as +(a-z). You can also use [:alpha:] in place of (a-z) so this example uses both.

SHOULD SAY:
"This is expressed as +([a-z]). You can also use ([:alpha:]) in place of (a-z) so this example uses both.
10/09/2013

595Text correction: Error in code under "File Comparison Tests"
The second to last line of code on the page, Files file1 and file4 differ
should be deleted.
2/7/14

7157Text correction: Error in code under "Indirection"
In the first line of code, "mything" should read "myvar"
2/7/14

8194Text correction: Error under "GETOPTS"
In the first paragraph, starting with the third sentence:
"getopts displays the error message "option requires an argument -- i" but continues executing. The usage message is displayed when the script later checks if $# is equal to 2, which in this case is not true"

should read:

"getopts displays the error message "option requires an argument -- i" but continues executing with argv set to "?" which causes the usage() function to be called. usage() displays a message and exits the script. The usage message would have been displayed anyway, when the script later checks if $# is equal to 2, which in this case is not true."
4/16/14

9215Text correction: Error under "Deleting from an Array"
The first paagraph on the page:
"Using unset activities[7] has largely the same effect. As discussed in Chapter 7, there is a difference between setting a variable to the empty string and unsetting it entirely, but it is obvious only when the ${variable+string} or ${variable?string} forms are used."

Should read:

"Using unset activities[7] has largely the same effect. As discussed in Chapter 7, there is a difference between setting a variable to the empty string and unsetting it entirely, but it is obvious only when the ${variable+string} or ${variable?string} forms are used. In the case of an array, it also has the effect of decrementing the size of ${#activities[@]}."

The first set of output on the page should not include the line "Activity 11: parachuting"
4/15/14

12295Text Correction: Error in Code
295-296, code under DF header, line 6
CURRENTLY READS
available=`df -k /var | awk '{ print $4 }' | tail -1`
SHOULD READ
available=`df -k ${preferred} | awk '{ print $4 }' | tail -1`
08/22/14

12310Text Correction: Error in Code
Lines 4-6
Currently Reads:
matches=0
comparisons=0
combinations=0
Should Read:
--blank--
08/27/14

12311Text Correction: Error in Code
Lines 97-98
Currently Reads:
logmsg 2 "`date`: Done. `basename $0` found $matches matches in $comparisons comparisons."
logmsg 2 "Compared `wc -l $MD5 | awk '{ print $1 }'` files; that makes for $combinations combinations."
Should Read
--blank--
08/27/14

39Text Correction: Error in Code
Currently reads:
(The if statement would more commonly be written the other way around, if [ ?$#? -ne ?2? ] rather than if [?$#? -ne ?2? ], but this is hopefully more clear for this example.)
this should read:
(The if statement would more commonly be written the other way around, if [ ?$#? -ne ?2? ] rather than if [ ?$#? -eq ?2? ], but this is hopefully more clear for this example.)
04/02/15