ebook img

Linux Shell Scripting with Bash PDF

433 Pages·2005·4.48 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Linux Shell Scripting with Bash

TEAM LinG Linux Shell Scripting with Bash TEAM LinG Linux Shell Scripting with Bash Ken O.Burtch DEVELOPER’S LIBRARY Sams Publishing,800 East 96th Street,Indianapolis,Indiana 46240 Linux Shell Scripting with Bash Acquisitions Editor Scott Meyers Copyright © 2004 by Sams Publishing All rights reserved.No part of this book shall be reproduced,stored Managing Editor in a retrieval system,or transmitted by any means,electronic, Charlotte Clapp mechanical,photocopying,recording,or otherwise,without written Project Editor permission from the publisher.No patent liability is assumed with Elizabeth Finney respect to the use of the information contained herein.Although every precaution has been taken in the preparation of this book,the Copy Editor publisher and author assume no responsibility for errors or omis- Kezia Endsley sions.Nor is any liability assumed for damages resulting from the use Indexer of the information contained herein. Ken Johnson International Standard Book Number:0-672-32642-6 Proofreader Library of Congress Catalog Card Number:2003112582 Leslie Joseph Printed in the United States of America Technical Editor First Printing:February 2004 John Traenkenschuh 07 06 05 04 4 3 2 1 Publishing Coordinator Trademarks Vanessa Evans All terms mentioned in this book that are known to be trademarks Multimedia Developer or service marks have been appropriately capitalized.Sams Dan Scherf Publishing cannot attest to the accuracy of this information.Use of a Designer term in this book should not be regarded as affecting the validity of Gary Adair any trademark or service mark. Page Layout Warning and Disclaimer Brad Chinn Susan Geiselman Every effort has been made to make this book as complete and as accurate as possible,but no warranty or fitness is implied.The infor- mation provided is on an “as is”basis.The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book. Bulk Sales Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales.For more information,please contact U.S.Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S.,please contact International Sales 1-317-428-3341 [email protected] ❖ To F.Ray Skilton Professor and Author Who taught me more about computers over tea than I ever learned in a lecture hall. ❖ Contents at a Glance Introduction 1 1 The Linux Environment 7 2 Operating the Shell 13 3 Files,Users,and Shell Customization 27 4 Script Basics 51 5 Variables 67 6 Expressions 87 7 Compound Commands 115 8 Debugging and Version Control 125 9 Parameters and Subshells 145 10 Job Control and Signals 157 11 Text File Basics 169 12 Text File Processing 207 13 Console Scripting 233 14 Functions and Script Execution 249 15 Shell Security 267 16 Network Programming 281 17 Data Structures and Databases 301 18 Final Topics 319 A Complete Example 337 B Summary of Bash Built-In Commands 355 C Bash Options 357 D Error Codes 361 E Signals 365 F ASCII Table 367 Glossary 371 Index 375 Table of Contents 1 The Linux Environment 7 The Origin of Linux 7 Files and File Systems 8 Directories 9 Inodes and Links 10 Pipe and Socket Files 11 Device Files 11 2 Operating the Shell 13 Bash Keywords 13 Command Basics 13 Command-Line Editing 15 Variable Assignments and Displaying Messages 17 Multiple Commands 18 Command History 19 Directory Commands 21 Specialized Navigation and History 23 The Colon Command 24 Reference Section 24 date Command Switches 24 stty Command Switches 24 history Command Switches 25 pwd Command Switches 25 dirs Command Switches 25 3 Files,Users,and Shell Customization 27 Listing Files 27 printf Command 28 Getting Help 31 Fixing the Display 32 Working with Files 32 viii Contents Working with People 35 Shell Aliases 36 The Bash Hash Table 36 Customizing Your Prompt 37 Long Command Lines 39 Customizing Command-Line Editing 39 Your Session Profile 42 Reference Section 45 ls Command Switches 45 printf Formatting Codes 47 printf Backslash Codes 47 rm Command Switches 48 cp Command Switches 48 mv Command Switches 49 4 Script Basics 51 Creating a Script 51 Creating a Well-Behaved Script 52 The Header 53 Global Declarations 54 Sanity Checks 54 The Main Script 55 Cleanup 55 Stopping a Script 57 Reading Keyboard Input 57 Basic Redirection 58 Standard Output,Error,and Input 60 Built-In Versus Linux Commands 62 The Set and Shopt Commands 63 Reference Section 64 command Command Switches 64 enable Command Switches 64 read Command Switches 64 suspend Command Switches 65 Contents ix 5 Variables 67 Variable Basics 67 Predefined Variables 69 The Effect of Quotations 70 Variable Attributes 73 Arrays 74 Exporting Variables and the Linux Environment 76 The eval Command 78 story.bash:A Story Generator 80 Reference Section 82 Declare Command Switches 82 Bash Predefined Variables 82 6 Expressions 87 Expansions 87 The Basic if Command 88 File Expressions 89 Multiple Tests 90 Strings 92 Arithmetic Expressions 93 Logical Expressions 95 Relational Operations 96 Bitwise Operations 96 Self-Referential Operations 97 Other let Features 98 temperature.bash:Converting Fahrenheit to Celsius 99 Arithmetic Tests 100 Pattern Recognition 101 Globbing Options 104 Filename Brace Expansion ( {..} ) 104 Dollar Sign Substitutions 105 ANSI C Escape Expansion ($’) 105 Locale Translation ($”) 105

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.