04.Shell-scripting.pdf

(636 KB) Pobierz
134689968 UNPDF
Shell Scripting
Hamish Whittal
Shell Scripting
by Hamish Whittal
Published 2005-01-25 22:36:19
Copyright © 2004 The Shuttleworth Foundation
Unless otherwise expressly stated, all original material of whatever nature created by the contributors of the Learn
Linux community, is licensed under the Creative Commons [http://creativecommons.org/] license
[http://creativecommons.org/licenses/by-sa/2.0/].
What follows is a copy of the "human-readable summary" of this document. The Legal Code (full license) may be
read here [http://creativecommons.org/licenses/by-sa/2.0/legalcode/].
You are free:
• to copy, distribute, display, and perform the work
• to make derivative works
• to make commercial use of the work
Under the following conditions:
Attribution. You must give the original author credit.
Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only
under a license identical to this one.
• For any reuse or distribution, you must make clear to others the license terms of this work.
• Any of these conditions can be waived if you get permission from the copyright holder.
Your fair use and other rights are in no way affected by the above.
This is a human-readable summary of the Legal Code (the full license)
[http://creativecommons.org/licenses/by-sa/2.0/legalcode/].
134689968.001.png
134689968.002.png
134689968.003.png
Table of Contents
1. Tour de Shell Scripting ...........................................................................1
Introduction to the Course structure ....................................................1
Adage 1.0: ................................................................................1
What you will need ....................................................................1
What is Shell Scripting ..............................................................2
Introduction to info, man and the whatis database ................................4
info pages .................................................................................4
Man Pages ................................................................................9
The whatis Database ................................................................12
Revising some Basic Commands ......................................................13
The who command ..................................................................14
The w Command .....................................................................16
The "date" command ...............................................................17
The 'echo' command ................................................................20
File Commands .......................................................................23
System Commands ..................................................................29
stdin, stdout, stderr ..........................................................................33
stdin .......................................................................................34
stdout ......................................................................................34
Using stdin and stdout simultaneously .......................................37
Appending to a file ..................................................................37
stderr ......................................................................................38
stdout, stderr and using the ampersand (&) ................................40
Exercises: ................................................................................41
Unamed Pipes .........................................................................41
2. The Shell .............................................................................................45
Introduction ....................................................................................45
What is the login shell? ....................................................................46
Exercises .................................................................................48
The job of the shell ..........................................................................50
Command Interpreter ...............................................................50
Allows for variables to be set ....................................................51
I/O redirection .........................................................................51
Pipelines .................................................................................51
Customising your environment .................................................51
Conclusion: .............................................................................51
3. Regular Expressions .............................................................................53
Introduction ....................................................................................53
What are regular expressions? ..........................................................53
The fullstop .............................................................................54
Let's explore "sed" syntax ........................................................55
134689968.004.png
Zgłoś jeśli naruszono regulamin