Cover image for Linux shells by example
Title:
Linux shells by example
Author:
Quigley, Ellie.
Personal Author:
Publication Information:
Upper Saddle River, N.J. : Prentice Hall PTR, [2000]

©2000
Physical Description:
xviii, 761 pages : illustrations ; 24 cm + 1 computer laser optical disc (4 3/4 in.)
Language:
English
Title Subject:
ISBN:
9780130147110
Format :
Book

Available:*

Library
Call Number
Material Type
Home Location
Status
Central Library QA76.76.O63 Q538 2000 Book and Software Set Central Closed Stacks
Searching...

On Order

Summary

Summary

A tutorial to two Linux shells (bash and tcsh) and three shell programming utilities (grep, sed, and gawk). Each concept is captured is captured in a small concept, followed by the output and an explanation of each line of the program. The CD-ROM contains all of the source code and datafiles that are in the book. Annotation copyrighted by Book News, Inc., Portland, OR


Author Notes

ELLIE QUIGLEY is author of Perl by Example and UNIX Shells by Example and creator of the world's #1 interactive Perl course, Perl Multimedia Cyber Classroom. A leading instructor and trainer, her courses in Perl and UNIX shell programming at the University of California Santa Cruz Extension Program and at Sun Microsystems have become legendary throughout Silicon Valley.


Table of Contents

Prefacep. XVII
Acknowledgmentsp. XVIII
Chapter 1 Introduction to Linux Shellsp. 1
1.1 Why Linux?p. 1
1.1.1 What Is POSIX?p. 2
1.2 Definition and Function of a Shellp. 2
1.2.1 The Three Major UNIX Shellsp. 3
1.2.2 The Major Linux Shellsp. 4
1.2.3 History of the Shellsp. 5
1.2.4 What Shells This Book Coversp. 6
1.2.5 Uses of a Shellp. 6
1.2.6 Responsibilities of the Shellp. 6
1.3 System Startup and the Login Shellp. 7
1.3.1 Parsing the Command Linep. 8
1.3.2 Types of Commandsp. 8
1.4 Processes and the Shellp. 9
1.4.1 What Is a Process?p. 9
1.4.2 What Is a System Call?p. 9
1.4.3 What Processes Are Running?p. 11
1.4.4 System Calls for Creating and Terminating Processesp. 12
1.5 The Environment and Inheritancep. 16
1.5.1 Ownershipp. 16
1.5.2 The File Creation Maskp. 16
1.5.3 Changing Ownership and Permissionsp. 17
1.5.4 The Working Directoryp. 20
1.5.5 Variablesp. 20
1.5.6 Redirection and Pipesp. 21
1.5.7 The Shell and Signalsp. 28
1.6 Executing Commands from Scriptsp. 30
1.6.1 Sample Scripts: Comparing Shellsp. 31
1.6.2 The TC Shell Scriptp. 31
1.6.3 The C Shell Scriptp. 33
1.6.4 The Bourne Again Shell Scriptp. 34
1.6.5 The Bourne Shell Scriptp. 36
1.6.6 The Korn Shell Scriptp. 38
Chapter 2 The Linux Tool Boxp. 41
2.1 Regular Expressionsp. 41
2.1.1 Definition and Examplep. 41
2.1.2 Regular Expression Metacharactersp. 43
2.2 Combining Regular Expression Metacharactersp. 49
2.2.1 More Regular Expression Metacharactersp. 50
Chapter 3 The Grep Family (Gun and Sons)p. 55
3.1 The grep Commandp. 55
3.1.1 The Meaning of grepp. 55
3.1.2 How grep Worksp. 56
3.1.3 Basic and Extended Regular Expressionsp. 57
3.1.4 grep and Exit Statusp. 61
3.1.5 Regular grep Examples (grep, grep -G)p. 61
3.2 Extended grep (grep -E or egrep)p. 68
3.2.1 Extended grep Examples (egrep and grep -E)p. 70
3.2.2 Anomalies with Regular and Extended Variants of grepp. 73
3.3 Fixed grep (grep -F and fgrep)p. 76
3.4 Recursive grep (rgrep)p. 77
3.5 grep with Pipesp. 77
3.6 grep with Optionsp. 77
3.6.1 Gnu grep Options Examplesp. 82
3.6.2 Regular grep Review (grep -G)p. 88
3.6.3 egrep and grep -E Reviewp. 89
Linux Tools Lab 1p. 90
Chapter 4 The Streamlined Editorp. 93
4.1 What Is sed?p. 93
4.2 Versions of sedp. 93
4.3 How Does sed Work?p. 94
4.4 Addressingp. 94
4.5 Commands and Optionsp. 95
4.6 Error Messages and Exit Statusp. 98
4.6.1 Metacharactersp. 99
4.7 sed Examplesp. 100
4.7.1 Printing: The p Command (and the --quiet option)p. 100
4.7.2 Deleting: The d Commandp. 102
4.7.3 Substitution: The s Commandp. 103
4.7.4 Range of Selected Lines: The Commap. 106
4.7.5 Multiple Edits: The e Commandp. 107
4.7.6 Reading from Files: The r Commandp. 108
4.7.7 Writing to Files: The w Commandp. 109
4.7.8 Appending: The a Commandp. 109
4.7.9 Inserting: The i Commandp. 110
4.7.10 Next: The n Commandp. 111
4.7.11 Transform: The y Commandp. 111
4.7.12 Quit: The q Commandp. 112
4.7.13 Holding and Getting: The h and g Commandsp. 113
4.7.14 Holding and Exchanging: The h and x Commandsp. 117
4.8 sed Scriptingp. 117
4.8.1 sed Script Examplesp. 118
4.8.2 sed Reviewp. 121
Linux Tools Lab 2p. 122
Chapter 5 The Gawk Utility: Gawk as a Linux Toolp. 125
5.1 What's awk? What's nawk? What's gawk?p. 125
5.1.1 What Does awk Stand for?p. 125
5.1.2 Which awk?p. 126
5.2 awk's Formatp. 127
5.2.1 Input from Filesp. 127
5.2.2 Input from Commandsp. 128
5.2.3 awk Command-Line Optionsp. 129
5.3 Formatting Outputp. 131
5.3.1 The print Functionp. 131
5.3.2 The OFMT Variablep. 133
5.3.3 The printf Functionp. 133
5.4 awk Commands from within a Filep. 136
5.5 Records and Fieldsp. 138
5.5.1 Recordsp. 138
5.5.2 Fieldsp. 139
5.5.3 Field Separatorsp. 140
5.6 Patterns and Actionsp. 142
5.6.1 Patternsp. 142
5.6.2 Actionsp. 143
5.7 Regular Expressionsp. 144
5.7.1 The Match Operatorp. 148
5.8 awk Commands in a Script Filep. 149
5.9 Reviewp. 150
5.9.1 Simple Pattern Matchingp. 150
5.9.2 Simple Actionsp. 151
5.9.3 Regular Expressions in Pattern and Action Combinationsp. 154
5.9.4 Input Field Separatorsp. 157
5.9.5 awk Scriptingp. 160
Linux Tools Lab 3p. 160
Chapter 6 The Gawk Utility: Evaluating Expressionsp. 163
6.1 Comparison Expressionsp. 163
6.1.1 Relational Operatorsp. 163
6.1.2 Conditional Expressionsp. 164
6.1.3 Computationp. 165
6.1.4 Compound Patternsp. 166
6.1.5 Range Patternsp. 167
6.1.6 A Data Validation Programp. 168
6.2 Reviewp. 169
6.2.1 Equality Testingp. 169
6.2.2 Relational Operatorsp. 170
6.2.3 Logical Operatorsp. 172
6.2.4 Logical Not Operatorp. 173
6.2.5 Arithmetic Operatorsp. 173
6.2.6 Range Operatorp. 176
6.2.7 Conditional Operatorp. 177
6.2.8 Assignment Operatorsp. 177
Linux Tools Lab 4p. 178
Chapter 7 The Gawk Utility: Gawk Programmingp. 181
7.1 Variablesp. 181
7.1.1 Numeric and String Constantsp. 181
7.1.2 User-Defined Variablesp. 182
7.1.3 Begin Patternsp. 186
7.1.4 End Patternsp. 187
7.2 Redirection and Pipesp. 187
7.2.1 Output Redirectionp. 187
7.2.2 Input Redirection (getline)p. 188
7.3 Pipesp. 190
7.4 Closing Files and Pipesp. 191
7.5 Reviewp. 192
7.5.1 Increment and Decrement Operatorsp. 192
7.5.2 Built-In Variablesp. 194
7.5.3 BEGIN Patternsp. 198
7.5.4 END Patternsp. 200
7.5.5 awk Script with BEGIN and ENDp. 201
7.5.6 The printf Functionp. 202
7.5.7 Redirection and Pipesp. 204
7.5.8 Opening and Closing a Pipep. 204
Linux Tools Lab 5p. 206
7.6 Conditional Statementsp. 207
7.6.1 if Statementsp. 207
7.6.2 if/else Statementsp. 207
7.6.3 if/else else if Statementsp. 208
7.7 Loopsp. 210
7.7.1 while Loopp. 210
7.7.2 for Loopp. 210
7.7.3 Loop Controlp. 211
7.8 Program Control Statementsp. 212
7.8.1 next Statementp. 212
7.8.2 exit Statementp. 212
7.9 Arraysp. 213
7.9.1 Subscripts for Associative Arraysp. 213
7.9.2 Processing Command Arguments in awkp. 220
7.10 awk Built-In Functionsp. 222
7.10.1 String Functionsp. 222
7.10.2 Time Functionsp. 227
7.10.3 Built-In Arithmetic Functionsp. 229
7.10.4 Integer Functionp. 230
7.10.5 Random Number Generatorp. 230
7.11 User-Defined Functionsp. 231
7.12 Reviewp. 233
Linux Tools Lab 6p. 238
7.13 Odds and Endsp. 239
7.13.1 Fixed Fieldsp. 239
7.13.2 Bundling and Unbundling Filesp. 242
7.13.3 Multiline Recordsp. 243
7.13.4 Generating Form Lettersp. 244
7.13.5 Interaction with the Shellp. 247
7.14 Reviewp. 248
7.14.1 String Functionsp. 248
7.14.2 Command Line Argumentsp. 252
7.14.3 Reading Input (getline)p. 253
7.14.4 Control Functionsp. 255
7.14.5 User-Defined Functionsp. 256
Linux Tools Lab 7p. 257
Chapter 8 The Interactive Bash Shellp. 259
8.1 Introductionp. 259
8.1.1 Versions of Bashp. 259
8.1.2 Startupp. 260
8.1.3 The Environmentp. 262
8.1.4 Setting Bash Options with the Built-In set and shopt Commandsp. 270
8.1.5 The Promptsp. 275
8.1.6 The Command Linep. 281
8.1.7 Job Controlp. 288
8.2 Command Line Shortcutsp. 291
8.2.1 Command and Filename Completionp. 291
8.2.2 Historyp. 292
8.2.3 Accessing Commands from the History Filep. 293
8.2.4 The Readline Library and Binding Keysp. 306
8.2.5 Aliasesp. 314
8.2.6 Manipulating the Directory Stackp. 315
8.2.7 Metacharacters (Wildcards)p. 317
8.2.8 Filename Substitution (Globbing)p. 318
8.3 Variablesp. 327
8.3.1 Local Variables and Scopep. 328
8.3.2 Environment Variablesp. 331
8.3.3 Quotingp. 350
8.3.4 Command Substitutionp. 353
8.3.5 Arithmetic Expansionp. 356
8.3.6 Order of Expansionp. 357
8.3.7 Arrays (Versions 2.x)p. 357
8.3.8 Functions (Introduction)p. 360
8.3.9 Standard I/O and Redirectionp. 363
8.3.10 Pipesp. 368
8.3.11 The Here Document and Redirecting Inputp. 370
8.3.12 Shell Invocation Optionsp. 372
8.3.13 The set Command and Optionsp. 373
8.3.14 The shopt Command and Optionsp. 375
8.3.15 Shell Built-In Commandsp. 377
The Bourne Shell Lab Exercisesp. 380
Chapter 9 Programming with the Bash Shellp. 385
9.1 Introductionp. 385
9.1.1 The Steps in Creating a Shell Scriptp. 385
9.2 Reading User Inputp. 388
9.2.1 Variables (Review)p. 388
9.2.2 The read Commandp. 388
9.3 Arithmeticp. 391
9.3.1 Integers (declare and let Commands)p. 391
9.3.2 Floating Point Arithmeticp. 395
9.4 Positional Parameters and Command Line Argumentsp. 396
9.4.1 Positional Parametersp. 396
9.4.2 The set Command and Positional Parametersp. 397
9.5 Conditional Constructs and Flow Controlp. 401
9.5.1 Exit Statusp. 401
9.5.2 The Built-In test Commandp. 402
9.5.3 The if Commandp. 407
9.5.4 The if/else Commandp. 413
9.5.5 The if/elif/else Commandp. 415
9.5.6 File Testingp. 418
9.5.7 The null Commandp. 420
9.5.8 The case Commandp. 422
9.6 Looping Commandsp. 425
9.6.1 The for Commandp. 425
9.6.2 The while Commandp. 430
9.6.3 The until Commandp. 433
9.6.4 The select Command and Menusp. 435
9.6.5 Looping Commandsp. 440
9.6.6 I/O Redirection and Subshellsp. 446
9.6.7 IFS and Loopsp. 449
9.7 Functionsp. 450
9.7.1 Function Arguments and the Return Valuep. 452
9.7.2 Functions and the source (or dot) Commandp. 455
9.8 Trapping Signalsp. 459
9.9 Debuggingp. 464
9.10 Processing Command Line Options with getoptsp. 466
9.11 The eval Command and Parsing the Command Linep. 472
9.12 Bash Optionsp. 474
9.12.1 Shell Invocation Optionsp. 474
9.12.2 The set Command and Optionsp. 476
9.12.3 The shopt Command and Optionsp. 479
9.13 Shell Built-In Commandsp. 480
The Bash Shell Lab Exercisesp. 483
Chapter 10 The Interactive TC Shellp. 491
10.1 Introductionp. 491
10.1.1 Versions of tcshp. 491
10.1.2 Startupp. 492
10.2 The TC Shell Environmentp. 494
10.2.1 Initialization Filesp. 494
10.2.2 The Search Pathp. 499
10.2.3 The Shell Promptsp. 500
10.2.4 The Command Linep. 504
10.3 Command Line Shortcutsp. 508
10.3.1 Historyp. 508
10.3.2 The Built-In Command Line Editorsp. 517
10.3.3 Command, Filename, and Variable Completionp. 524
10.3.4 Manipulating the Directory Stackp. 533
10.3.5 Spelling Correctionp. 536
10.3.6 Aliasesp. 537
10.4 Job Controlp. 540
10.4.1 Background Jobsp. 541
10.4.2 Foreground and Background Commandsp. 543
10.4.3 Scheduling Jobsp. 544
10.5 Metacharactersp. 546
10.5.1 Filename Substitutionp. 547
10.6 Redirection and Pipesp. 552
10.6.1 Redirecting Inputp. 553
10.6.2 The Here Documentp. 553
10.6.3 Redirecting Outputp. 555
10.7 Variablesp. 561
10.7.1 Printing the Values of Variablesp. 562
10.7.2 Local Variables (Visibility and Naming)p. 567
10.7.3 Environment Variablesp. 569
10.8 Arraysp. 572
10.8.1 What Is an Array?p. 572
10.9 Special Variables and Modifiersp. 576
10.9.1 Pathname Variable Modifiersp. 578
10.9.2 Upper- and Lowercase Modifiersp. 579
10.10 Command Substitutionp. 580
10.10.1 Backquotesp. 580
10.11 Quotingp. 583
10.11.1 The Backslashp. 583
10.11.2 Single Quotesp. 585
10.11.3 Double Quotesp. 586
10.11.4 Combining Double and Single Quotesp. 586
10.11.5 Steps to Successful Quotingp. 587
10.11.6 Quoting Variablesp. 588
10.12 Built-In Commandsp. 590
10.12.1 Special Aliases (tcsh Only)p. 602
10.12.2 Special Built-In Shell Variablesp. 602
The TC Shell Lab Exercisesp. 610
Chapter 11 Programming with the TC Shellp. 615
11.1 Steps in Creating a Shell Scriptp. 615
11.1.1 The First Linep. 615
11.1.2 Commentsp. 616
11.1.3 Making the Script Executablep. 616
11.1.4 An Example Scripting Sessionp. 616
11.1.5 Variables (Review)p. 617
11.2 Reading User Inputp. 618
11.2.1 The $[ Variablep. 618
11.2.2 Creating a Wordlist from the Input Stringp. 619
11.3 Arithmeticp. 620
11.3.1 Arithmetic Operatorsp. 620
11.3.2 Floating Point Arithmeticp. 622
11.4 Debugging Scriptsp. 622
11.5 Command Line Argumentsp. 625
11.5.1 Positional Parameters and argvp. 625
11.6 Flow Control and Conditional Constructsp. 627
11.6.1 Testing Expressionsp. 627
11.6.2 The if Statementp. 629
11.6.3 The if/else Statementsp. 631
11.6.4 Debugging Expressionsp. 632
11.6.5 The if statement and a Single Commandp. 633
11.6.6 The if/else if Statementsp. 633
11.6.7 Exit Status and the Status Variablep. 634
11.6.8 Exiting from a Shell Scriptp. 635
11.6.9 Using the Status Variable in a Scriptp. 636
11.6.10 Evaluating Commands within Conditionalsp. 636
11.6.11 The gotop. 638
11.6.12 File Testingp. 639
11.6.13 Nesting Conditionalsp. 643
11.6.14 The switch Commandp. 645
11.6.15 The Here Document and Menusp. 648
11.7 Loopsp. 650
11.7.1 The foreach Loopp. 650
11.7.2 The while Loopp. 653
11.7.3 The repeat Commandp. 655
11.7.4 Looping Commandsp. 655
11.8 Interrupt Handlingp. 660
11.9 setuid Scriptsp. 661
11.10 Storing Scriptsp. 662
11.11 Built-In Commandsp. 663
11.11.1 Shell Command Line Switchesp. 663
The TC Shell Lab Exercisesp. 665
Appendix A Useful Linux/Unix Utilities for Shell Programmersp. 671
Appendix B Comparison of the Shellsp. 735
B.1 tcsh versus cshp. 736
B.2 bash versus shp. 736
Appendix C Steps for Using Quoting Correctlyp. 745
Indexp. 749

Google Preview