Introduction. Comtrol DeviceMaster Software Development Kit
Quảng cáo
Quảng cáo
Introduction
1. 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.
2. 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.
Introduction 1
Bash Guide for Beginners
3. New versions, translations and availability
The most recent edition can be found at http://tille.garrels.be/training/bash/. You should find the same version at http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html.
This guide is available in print from Fultus.com.
Figure 1. Bash Guide for Beginners front cover
This guide has been translated:
• Chinese translation at http://xiaowang.net/bgb-cn/, by Wang Wei.
• Ukrainian translation at http://docs.linux.org.ua/index.php/LDP:Bash_beginners_guide, by Yaroslav
Fedevych and his team.
A french translation is in the making and will be linked to as soon as it is finished.
4. Revision History
Revision History
Revision 1.11
2008-12-27 Revised by: MG
Processed input from readers.
Revision 1.10
2008-06-06 address change
Revision 1.9
2006-10-10
Incorporated reader remarks, added index using DocBook tags.
Revised by: MG
Revised by: MG
Revision 1.8
2006-03-15 Revised by: MG clarified example in Chap4, corrected here doc in chap9, general checks and correction of typos, added link to Chinese and Ukrainian translation, note and stuff to know about awk in chap6.
Revision 1.7
2005-09-05 Revised by: MG
Corrected typos in chapter 3, 6 and 7, incorporated user remarks, added a note in chap7.
Introduction 2
Bash Guide for Beginners
Revision 1.6
2005-03-01 Revised by: MG
Minor debugging, added more keywords, info about new Bash 3.0, took out blank image.
Revision 1.0
2004-04-27 Revised by: TM
Initial release for LDP; more exercises, more markup, less errors and abuse; added glossary.
Revision 1.0-beta
Pre-release
2003-04-20 Revised by: MG
5. 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 ;-)
6. Feedback
Missing information, missing links, missing characters, remarks? Mail it to
<tille wants no spam _at_ garrels dot be> the maintainer of this document.
7. Copyright information
* Copyright (c) 2002-2007, Machtelt Garrels
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the author, Machtelt Garrels, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Introduction 3
Bash Guide for Beginners
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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.
8. 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.
9. Conventions used in this document
The following typographic and usage conventions occur in this text:
Table 1. Typographic and usage conventions
Text type
"Quoted text" terminal view
command
VARIABLE option
argument
command options
arguments
filename
Key
Button
Menu->Choice
Terminology
\
Introduction
Meaning
Quotes from people, quoted computer output.
Literal computer input and output captured from the terminal, usually rendered with a light grey background.
Name of a command that can be entered on the command line.
Name of a variable or pointer to content of a variable, as in
$VARNAME
.
Option to a command, as in "the
-a
option to the ls command".
Argument to a command, as in "read man
ls
".
Command synopsis or general usage, on a separated line.
Name of a file or directory, for example "Change to the
/usr/bin
directory."
Keys to hit on the keyboard, such as "type Q to quit".
Graphical button to click, like the OK button.
Choice to select from a graphical menu, for instance: "Select Help->About Mozilla in your browser."
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
4
The author
Bash Guide for Beginners
"Don't press Enter yet!" link to related subject within this guide.
Clickable link to an external web resource.
10. 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.
•
Chapter 1: Bash basics: why Bash is so good, building blocks, first guidelines on developing good
scripts.
•
Chapter 2: Script basics: writing and debugging.
•
order, aliases, options.
•
Chapter 4: Regular expressions: an introduction.
•
Chapter 5: Sed: an introduction to the sed line editor.
•
Chapter 6:Awk: introduction to the awk programming language.
•
Chapter 7: Conditional statements: constructs used in Bash to test conditions.
•
Chapter 8: Interactive scripts: making scripts user-friendly, catching user input.
•
Chapter 9: Executing commands repetitively: constructs used in Bash to automate command
execution.
•
Chapter 10: Advanced variables: specifying variable types, introduction to arrays of variables,
operations on variables.
•
Chapter 11: Functions: an introduction.
•
Chapter 12: Catching signals: introduction to process signalling, trapping user-sent signals.
Introduction 5
Tải xuống
Quảng cáo