Shell Scripting
Expert Recipes for Linux, Bash, and more
Häftad, Engelska, 2011
Av Steve Parker
499 kr
Beställningsvara. Skickas inom 7-10 vardagar
Fri frakt för medlemmar vid köp för minst 249 kr.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!
Produktinformation
- Utgivningsdatum2011-08-26
- Mått188 x 236 x 29 mm
- Vikt1 007 g
- FormatHäftad
- SpråkEngelska
- Antal sidor608
- FörlagJohn Wiley & Sons Inc
- ISBN9781118024485
Tillhör följande kategorier
Steve Parker is an IT consultant specializing in Solaris and GNU/Linux. He has been providing consultancy services for more than a decade. He is the author of the popular Bourne Shell Programming/Scripting Tutorial (http://steve-parker.org/sh/sh.shtml), which sees more than one million visitors a year.
- Introduction xxixPart I: About the IngredientsChapter 1: The History of Unix, Gnu, and Linux 3Unix 3“Everything is a File” and Pipelines 5BSD 6GNU 7Linux 11Summary 12Chapter 2: Getting Started 15Choosing an OS 15GNU/Linux 15The BSDs 17Proprietary Unix 17Microsoft Windows 17Choosing an Editor 18Graphical Text Editors 18Terminal Emulation 21Nongraphical Text Editors 22Setting Up the Environment 24The Shell Profile 24Aliases 26vim Settings 30Summary 31Chapter 3: Variables 33Using Variables 33Typing 34Assigning Values to Variables 35Positional Parameters 39Return Codes 42Unsetting Variables 45Preset and Standard Variables 47BASH_ENV 47BASHOPTS 47SHELLOPTS 48BASH_COMMAND 50BASH_SOURCE, FUNCNAME, LINENO, and BASH_LINENO 51SHELL 55HOSTNAME and HOSTTYPE 55Working Directory 55PIPESTATUS 55TIMEFORMAT 56PPID 57RANDOM 58REPLY 58SECONDS 58BASH_XTRACEFD 59GLOBIGNORE 60HOME 62IFS 62PATH 63TMOUT 64TMPDIR 65User Identification Variables 65Summary 66Chapter 4: Wildcard Expansion 67Filename Expansion (Globbing) 67Bash Globbing Features 70Shell Options 71Regular Expressions and Quoting 75Overview of Regular Expressions 76Quoting 77Summary 81Chapter 5: Conditional Execution 83If/Then 83Else 85elif 85Test ([) 87Flags for Test 88File Comparison Tests 95String Comparison Tests 96Regular Expression Tests 98Numerical Tests 101Combining Tests 103Case 105Summary 109Chapter 6: Flow Control Using Loops 111For Loops 111When to Use for Loops 112Imaginative Ways of Feeding “for” with Data 112C-Style for Loops 118while Loops 119When to Use while Loops 119Ways to Use while Loops 119Nested Loops 125Breaking and Continuing Loop Execution 126while with Case 130until Loops 131select Loops 133Summary 137Chapter 7: Variables Continued 139Using Variables 139Variable Types 141Length of Variables 142Special String Operators 144Stripping Variable Strings by Length 144Stripping from the End of the String 146Stripping Strings with Patterns 147Searching Strings 151Using Search and Replace 151Replacing Patterns 153Deleting Patterns 153Changing Case 153Providing Default Values 153Indirection 157Sourcing Variables 158Summary 159Chapter 8: Functions and Libraries 161Functions 161Defining Functions 162Function Output 162Writing to a File 164Redirecting the Output of an Entire Function 167Functions with Trap 171Recursive Functions 173Variable Scope 177Libraries 181Creating and Accessing Libraries 183Library Structures 183Network Configuration Library 187Use of Libraries 191getopts 191Handling Errors 194getopts within Functions 195Summary 197Chapter 9: Arrays 199Assigning Arrays 199One at a Time 200All at Once 200By Index 201All at Once from a Source 201Read from Input 203Accessing Arrays 205Accessing by Index 205Length of Arrays 206Accessing by Variable Index 206Selecting Items from an Array 209Displaying the Entire Array 209Associative Arrays 210Manipulating Arrays 211Copying an Array 211Appending to an Array 213Deleting from an Array 214Advanced Techniques 216Summary 217Chapter 10: Processes 219The ps Command 219ps Line Length 220Parsing the Process Table Accurately 220killall 223The /proc pseudo-filesystem 225prtstat 226I/O Redirection 227Appending Output to an Existing File 229Permissions on Redirections 229exec 229Using exec to Replace the Existing Program 230Using exec to Change Redirection 231Pipelines 237Background Processing 237wait 238Catching Hangups with nohup 239Other Features of /proc and /sys 242Version 242SysRq 242/proc/meminfo 245/proc/cpuinfo 245/sys 246/sys/devices/system/node 251sysctl 253Summary 254Chapter 11: Choosing and Using Shells 255The Bourne Shell 256The KornShell 256The C Shell 256The Tenex C Shell 257The Z Shell 257The Bourne Again Shell 257The Debian Almquist Shell 258Dotfiles 258Interactive Login Shells 259Interactive Non-Login Shells 260Non-Interactive Shells 261Logout Scripts 262Command Prompts 262The PS1 Prompt 262The PS2, PS3, and PS4 Prompts 264Aliases 265Timesavers 265Modifying Behaviors 265History 266Recalling Commands 267Searching History 267Timestamps 268Tab Completion 269ksh 269tcsh 270zsh 270bash 271Foreground, Background, and Job Control 272Backgrounding Processes 272Job Control 273nohup and disown 275Summary 276Part II: Recipes For Using and Extending System ToolsChapter 12: File Manipulation 279stat 279cat 281Numbering Lines 282Dealing with Blank Lines 282Non-Printing Characters 283cat Backwards is tac 284Redirection 285Redirecting Output: The Single Greater-Than Arrow (>) 285Appending: The Double Greater-Than Arrow (>>) 286Input Redirection: The Single Less-Than Arrow ( << EOF) 290dd 292df 294mktemp 295join 297install 298grep 300grep Flags 300grep Regular Expressions 301split 303tee 304touch 306find 307find-exec 310Summary 313Chapter 13: Text Manipulation 315cut 315echo 316dial1 316dial2 319fmt 320head and tail 323Prizes 323World Cup 324od 328paste 331pr 334printf 335shuf 337Dice Thrower 337Card Dealer 338Travel Planner 340sort 341Sorting on Keys 342Sorting Log Files by Date and Time 344Sorting Human-Readable Numbers 345tr 346uniq 350wc 351Summary 352Chapter 14: Tools For Systems Administration 353basename 353date 355Typical Uses of date 355More Interesting Uses of date 359dirname 360factor 362identity, groups, and getent 364logger 367md5sum 368mkfi fo 370Master and Minions 371Reversing the Order 373Networking 375telnet 376netcat 376ping 378Scripting ssh and scp 381OpenSSL 383nohup 390seq 391Integer Sequences 391Floating Point Sequences 393sleep 394timeout 394Shutdown Script 396Network Timeout 399uname 400uuencode 401xargs 402yes 405Summary 406Part III: Recipes For Systems AdministrationChapter 15: Shell Features 409Recipe 15-1: Installing Init Scripts 409Technologies Used 410Concepts 410Potential Pitfalls 410Structure 410Recipe 412Invocation 414Summary 414Recipe 15-2: RPM Report 414Technologies Used 415Concepts 415Potential Pitfalls 415Structure 415Recipe 417Invocation 419Summary 420Recipe 15-3: Postinstall Scripts 421Technologies Used 421Concepts 421Potential Pitfalls 422Structure 422Recipe 423Invocation 425Summary 426Chapter 16: Systems Administration 427Recipe 16-1: init Scripts 427Technologies Used 428Concepts 428Potential Pitfalls 429Structure 430Recipe 431Invocation 432Summary 433Recipe 16-2: CGI Scripts 433Technologies Used 433Concepts 434Potential Pitfalls 434Structure 435Recipe 438Invocation 441Summary 445Recipe 16-3: Configuration Files 445Technologies Used 445Concepts 445Potential Pitfalls 446Structure 446Recipe 446Invocation 447Summary 448Recipe 16-4: Locks 448Technologies Used 448Concepts 448Potential Pitfalls 449Structure 450Recipe 453Invocation 455Summary 458Chapter 17: Presentation 459Recipe 17-1: Space Game 459Technologies Used 459Concepts 460Potential Pitfalls 462Structure 462Recipe 464Invocation 469Summary 470Chapter 18: Data Storage and Retrieval 471Recipe 18-1: Parsing HTML 471Technologies Used 471Concepts 472Potential Pitfalls 472Structure 472Recipe 473Invocation 474Summary 476Recipe 18-2: CSV Formatting 476Technologies Used 476Concepts 476Potential Pitfalls 477Structure 477Recipe 478Invocation 480Summary 481Chapter 19: Numbers 483Recipe 19-1: The Fibonacci Sequence 483Technologies Used 483Concepts 484Potential Pitfalls 484Structure for Method 1 485Recipe for Method 1 486Invocation of Method 1 486Structure for Method 2 487Recipes for Method 2 488Invocations of Method 2 489Structure for Method 3 490Recipe for Method 3 490Invocation of Method 3 491Summary 492Recipe 19-2: PXE Booting 492Technologies Used 492Concepts 493Potential Pitfalls 493Structure 493Recipe 494Invocation 497Summary 499Chapter 20: Processes 501Recipe 20-1: Process Control 501Technologies Used 501Concepts 502Potential Pitfalls 503Structure 503Recipe 506Invocation 511Summary 516Chapter 21: Internationalization 517Recipe 21-1: Internationalization 517Technologies Used 518Concepts 518Potential Pitfalls 519Structure 520Recipe 521Invocation 525Summary 526Part IV: ReferenceAppendix: Further Reading 529Shell Tutorials and Documentation 529Arrays 530Tools 530Unix Flavors 531Shell Services 531Glossary 533Index 539