Transcription of Bash Guide for Beginners
1 Bash Guide for BeginnersMachtelt GarrelsGarrels BVBA<tille wants no spam _at_ garrels dot be>Version Last updated 20081227 EditionTable of Why this Guide ?..12. Who should read this book?..13. New versions, translations and Revision Copyright What do you need?..49. Conventions used in this Organization of this 1. Bash and Bash Common shell General shell Shell Advantages of the Bourne Again Bash is the GNU Features only found in Executing Shell built-in Executing programs from a Building Shell building Developing good Properties of good A word on order and An example Bash script: Example init 2.
2 Writing and debugging Creating and running a Writing and Executing the Script Which shell will run the script?.. Adding Debugging Bash Debugging on the entire Debugging on part(s) of the Guide for BeginnersiTable of ContentsChapter 3. The Bash Shell initialization System-wide configuration Individual user configuration Changing shell configuration Types of Creating Exporting Reserved Special Script recycling with Quoting Why?.. Escape Single Double ANSI-C Shell Brace Tilde Shell parameter and variable Command Arithmetic Process Word File name What are aliases?
3 Creating and removing More Bash Displaying Changing 4. Regular Regular What are regular expressions?.. Regular expression Basic versus extended regular Examples using What is grep?.. Grep and regular Pattern matching using Bash Character Guide for BeginnersiiTable of ContentsChapter 4. Regular Character 5. The GNU sed stream What is sed?.. sed Interactive Printing lines containing a Deleting lines of input containing a Ranges of Find and replace with Non-interactive Reading sed commands from a Writing output 6.
4 The GNU awk programming Getting started with What is gawk?.. Gawk The print Printing selected Formatting The print command and regular Special Gawk Gawk The input field The output The number of User defined More The printf 7. Conditional Introduction to Simple applications of More advanced if if/then/else if/then/elif/else Nested if Guide for BeginnersiiiTable of ContentsChapter 7. Conditional Boolean Using the exit statement and Using case Simplified Initscript 8. Writing interactive Displaying user Interactive or not?
5 Using the echo built-in Catching user Using the read built-in Prompting for user Redirection and file File input and 9. Repetitive The for How does it work?.. The while What is it?.. The until What is it?.. I/O redirection and Input Output Break and The break The continue Making menus with the select The shift What does it do?.. Guide for BeginnersivTable of ContentsChapter 10. More on Types of General assignment of Using the declare Array Creating Dereferencing the variables in an Deleting array Examples of Operations on Arithmetic on Length of a Transformations of 11.
6 What are functions?.. Function Positional parameters in Displaying Examples of functions in Setting the Remote 12. Catching Usage of signals with How Bash interprets More A. Shell Common Differing Guide for BeginnersvTable of Guide for BeginnersviTable of Guide for BeginnersviiIntroduction1. Why this Guide ?The primary reason for writing this document is that a lot of readers feel the existing HOWTO to be too shortand incomplete, while the Bash Scripting Guide is too much of a reference work. There is nothing in betweenthese two extremes.
7 I also wrote this Guide on the general principal that not enough free basic courses areavailable, though they should is a practical Guide which, while not always being too serious, tries to give real-life instead of theoreticalexamples. I partly wrote it because I don't get excited with stripped down and over-simplified exampleswritten by people who know what they are talking about, showing some really cool Bash feature so much outof its context that you cannot ever use it in practical circumstances. You can read that sort of stuff afterfinishing this book, which contains exercises and examples that will help you survive in the real my experience as UNIX/Linux user, system administrator and trainer, I know that people can have yearsof daily interaction with their systems, without having the slightest knowledge of task automation.
8 Thus theyoften think that UNIX is not userfriendly, and even worse, they get the impression that it is slow andold-fashioned. This problem is another one that can be remedied by this Who should read this book?Everybody working on a UNIX or UNIX-like system who wants to make life easier on themselves, powerusers and sysadmins alike, can benefit from reading this book. Readers who already have a grasp of workingthe system using the command line will learn the ins and outs of shell scripting that ease execution of dailytasks. System administration relies a great deal on shell scripting; common tasks are often automated usingsimple scripts.
9 This document is full of examples that will encourage you to write your own and that willinspire you to improve on existing in this course:You should be an experienced UNIX or Linux user, familiar with basic commands, man pages anddocumentation Being able to use a text editor Understand system boot and shutdown processes, init and initscripts Create users and groups, set passwords Permissions, special modes Understand naming conventions for devices, partitioning, mounting/unmounting file systems Adding/removing software on your system See Introduction to Linux (or your local TLDP mirror)
10 If you haven't mastered one or more of these information can be found in your system documentation (man and info pages), or at the LinuxDocumentation New versions, translations and availabilityThe most recent edition can be found at You should find the same versionat Guide is available in print from 1. Bash Guide for Beginners front coverThis Guide has been translated:Chinese translation at , by Wang Wei. Ukrainian translation at :Bash_beginners_guide, by YaroslavFedevych and his team. A french translation is in the making and will be linked to as soon as it is Revision HistoryRevision HistoryRevision by: MGProcessed input from by: MGaddress changeRevision by: MGIncorporated reader remarks, added index using DocBook by: MGclarified example in Chap4, corrected here doc in chap9, general checks and correction of typos, added linkto Chinese and Ukrainian translation, note and stuff to know about awk in by: MGCorrected typos in chapter 3, 6 and 7, incorporated user remarks, added a note in Guide for BeginnersIntroduction2 Revision by.