]> Bash Guide for Beginners Machtelt Garrels Xalasys.com
tille wants no spam _at_ xalasys dot com
Version 1.5 Last updated 20041206 Linux Scripts linux Bash guide Guide Exercises exercises bash scripting Scripting
Introduction
Why this guide? The primary reason for writing this document is that a lot of readers feel the existing HOWTO to be too short and incomplete, while the Bash Scripting guide is too much of a reference work. There is nothing in between these two extremes. I also wrote this guide on the general principal that not enough free basic courses are available, though they should be. This is a practical guide which, while not always being too serious, tries to give real-life instead of theoretical examples. I partly wrote it because I don't get excited with stripped down and over-simplified examples written by people who know what they are talking about, showing some really cool Bash feature so much out of its context that you cannot ever use it in practical circumstances. You can read that sort of stuff after finishing this book, which contains exercises and examples that will help you survive in the real world. From my experience as UNIX/Linux user, system administrator and trainer, I know that people can have years of daily interaction with their systems, without having the slightest knowledge of task automation. Thus they often think that UNIX is not userfriendly, and even worse, they get the impression that it is slow and old-fashioned. This problem is another one that can be remedied by this guide.
Who should read this book? Everybody working on a UNIX or UNIX-like system who wants to make life easier on themselves, power users and sysadmins alike, can benefit from reading this book. Readers who already have a grasp of working the system using the command line will learn the ins and outs of shell scripting that ease execution of daily tasks. System administration relies a great deal on shell scripting; common tasks are often automated using simple scripts. This document is full of examples that will encourage you to write your own and that will inspire you to improve on existing scripts. Prerequisites/not in this course: You should be an experienced UNIX or Linux user, familiar with basic commands, man pages and documentation 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) if you haven't mastered one or more of these topics. Additional information can be found in your system documentation (man and info pages), or at the Linux Documentation Project.
New versions and availability The most recent edition can be found at . You should find the same version at . This guide is available in print from Fultus.com.
Bash Guide for Beginners front cover Front cover of the Bash guide, red highlighted code on blue background.
Revision History 1.5 2004-12-06 MG Changes because of new domain, minor corrections. 1.4 2004-10-18 MG Debugging, added a couple of notes in chap9, replaced screenshots with screen sections. Corrected some typos. 1.3 2004-07-09 MG Added tracer image 1x1 pixel http://tille.xalasys.com/images/blank-bash.png, added textobjects for all pictures, fixed wrong links in index, made signal list more clear. 1.2 2004-06-15 MG Added index, more markup in screen sections. 1.1 2004-05-22 MG Last read-through before going to press, added more examples, checked summaries, exercises, cleaned up introduction. 1.0 2004-04-27 TM Initial release for LDP; more exercises, more markup, less errors and abuse; added glossary. 1.0-beta 2003-04-20 MG Pre-release
Contributions Thanks to all the friends who helped (or tried to) and to my husband; your encouraging words made this work possible. Thanks to all the people who submitted bug reports, examples and remarks - among many, many others: Hans Bol, one of the groupies Mike Sim, remarks on style Dan Richter, for array examples Gerg Ferguson, for ideas on the title Mendel Leo Cooper, for making room #linux.be, for keeping my feet on the ground Frank Wang, for his detailed remarks on all the things I did wrong ;-) Special thanks to Tabatha Marshall, who volunteered to do a complete review and spell and grammar check. We make a great team: she works when I sleep. And vice versa ;-)
Feedback Missing information, missing links, missing characters, remarks? Mail it to
tille wants no spam _at_ xalasys dot com
the maintainer of this document.
Copyright information Copyright © 2003 Machtelt Garrels. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being "New versions of this document", "Contributions", "Feedback" and "Copyright information", with no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in entitled "GNU Free Documentation License". The author and publisher have made every effort in the preparation of this book to ensure the accuracy of the information. However, the information contained in this book is offered without warranty, either express or implied. Neither the author nor the publisher nor any dealer or distributor will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. The logos, trademarks and symbols used in this book are the properties of their respective owners.
What do you need? bash, available from http://www.gnu.org/directory/GNU/. The Bash shell is available on nearly every Linux system, and can these days be found on a wide variety of UNIX systems. Compiles easily if you need to make your own, tested on a wide variety of UNIX, Linux, MS Windows and other systems.
Conventions used in this document The following typographic and usage conventions occur in this text: Typographic and usage conventions Text typeMeaning Quoted text Quotes from people, quoted computer output. terminal view Literal computer input and output captured from the terminal, usually rendered with a light grey background. command Name of a command that can be entered on the command line. VARIABLE Name of a variable or pointer to content of a variable, as in $VARNAME. Option to a command, as in the option to the ls command. argument Argument to a command, as in read man ls. command arguments Command synopsis or general usage, on a separated line. filename Name of a file or directory, for example Change to the /usr/bin directory. Key Keys to hit on the keyboard, such as type Q to quit. Button Graphical button to click, like the OK button. MenuChoice Choice to select from a graphical menu, for instance: Select HelpAbout Mozilla in your browser. Terminology Important term or concept: The Linux kernel is the heart of the system. \ The backslash in a terminal view or command synopsis indicates an unfinished line. In other words, if you see a long command that is cut into multiple lines, \ means Don't press Enter yet! See link to related subject within this guide. The author Clickable link to an external web resource.
Organization of this document This guide discusses concepts useful in the daily life of the serious Bash user. While a basic knowledge of the usage of the shell is required, we start with a discussion of the basic shell components and practices in the first three chapters. Chapters four to six are discussions of basic tools that are commonly used in shell scripts. Chapters eight to twelve discuss the most common constructs in shell scripts. All chapters come with exercises that will test your preparedness for the next chapter. : Bash basics: why Bash is so good, building blocks, first guidelines on developing good scripts. : Script basics: writing and debugging. : The Bash Environment: initialization files, variables, quoting characters, shell expansion order, aliases, options. : Regular expressions: an introduction. : Sed: an introduction to the sed line editor. :Awk: introduction to the awk programming language. : Conditional statements: constructs used in Bash to test conditions. : Interactive scripts: making scripts user-friendly, catching user input. : Executing commands repetitively: constructs used in Bash to automate command execution. : Advanced variables: specifying variable types, introduction to arrays of variables, operations on variables. : Functions: an introduction. : Catching signals: introduction to process signalling, trapping user-sent signals.
&chap1; &chap2; &chap3; &chap4; &chap5; &chap6; &chap7; &chap8; &chap9; &chap10; &chap11; &chap12; &app1; &app2; &gloss; &index-gloss;