http://tldp.org/LDP/abs/html/
Advanced Bash Scripting Programming Guide
An in-depth exploration of scripting language art
This tutorial does not assume previous scripting or programming knowledge, but progresses quickly toward an intermediate/advanced level of instruction ... has been secretly in the small unix® wisdom and knowledge. It acts as a textbook, a handbook, self-taught, and as a source of reference and knowledge, Shell's scripting technology. Practice and a large number of comment examples please engage the reader, on the premise that the only way to really learn the script is to write a script.
This book is a general introduction to programming concepts suitable for classroom use.
This document is awarded to the public domain. No copyright!
Dedication
For Anita, the source of all the magic
Table of Contents
Part 1th. Introduction of Scenic Area
1. Shell Programming!
2. From the beginning of a sand-bang
Part 2nd. Basis
3. Special characters
4. Introduction to variables and parameters
5. Reference
6. Exit and exit status
7. Test
8. Operations and related Topics
Part 3rd. Beyond the basic
9. Another look at the variable
10. Manipulating variables
11. Loops and Branches
12. Command substitution
13. Operation Extension
14. Rest time
Part 4th. Command
15. Internal commands and internal
16. External filters, programs and commands
17. Systems and Administrative Orders
Part 5th. Advanced Topics
18. Regular expressions
19. Here's the file
20. Input/Output redirection
21st. Secondary shell layer
22. Restricted shell
23. Procedure Substitution
24. Function
25. Alias
26. List construction
27. Array
28. Indirect references
29. /Dev/proc
30. Network programming
31. 0 points and 0 points
32. Debugging
33. Options
34. Trap
35. Style of script
36. Miscellanies
37. Bash, version 2,3, and 4
38. Tail note
38.1. Author note
38.2. About the author
38.3. Where to go for help
38.4. The tool used to make the book
38.5. Credit
38.6. Disclaimer
Bibliography
Contribution Script
Reference Card
C. One sed and awk micro Primer
C. Sed
2. Awk
D. Parsing and managing paths
Exit codes with a special meaning
Details of input/output and I/O redirection
Command-Line Options
1. Standard command-line options
G. Bash command-line options
Important Documents
I. Important SYSTEM directory
Introduction to programmable completion
K Positioning
Historical command
M. Samples. Bash_profile file. BASHRC and.
Converting a batch file to a script
Movement
0.1. Parsing scripts
O. Writing scripts
Revision history
Download and mirror sites
Make a list
All rights reserved
T. ASCII table
Index
Table List
8-1. Operator Precedence
15-1. Job identifier
33-1. Options for Bash
36-1. The number represents the color in the escape sequence
B-1. Special Shell variables
B-2. Test operators: Binary comparison
B-3. Test operator: File
B-4. Parameter substitution and extension
B-5. String manipulation
B6. Miscellaneous construction
C-1. Basic commands
C-2. Examples of SED operators
E-1. Keep Exit codes
N-1. Keywords/variables/operators for batch files, and their shell equivalents
N-2. DOS commands and the corresponding UNIX
P-1. Revision history
Instance List
2-1. Cleanup: script/var/log cleanup of log files
2-2. Cleanup: An improved cleanup script
23. Cleanup: An enhanced and generalized version of the above script.
3-1. code block and input/output redirection
3-2. Save code block-to-file output
3-3. Run a loop in the background
3-4. Back up all the files changed on the last day
4-1. Variable assignment and substitution
4-2. Pure variable Assignment
4-3. Variable assignment, pure and imaginary
4-4. An integer or a string?
4-5. Position parameters
4-6. Wh,whois Domain Name Query
4-7. Shift
5-1. Strange variables.
5-2. Escape character
5-3. Detection keys
6-1. Exit/exit Status
6-2. Negative conditions to use!
7-1. What is truth?
7-2. Equivalence test,/usr/bin/test, [], and/usr/bin/[
7-3. Arithmetic Test (())
7-4. Disconnected test
7-5. Arithmetic and string comparisons
7-6. Test whether the string is empty
7-7. Zmore
8-1. Greatest common divisor
8-2. Using arithmetic operations
8-3. Using && and | | compound condition TEST
8-4. numeric constant representation
8-5. Manipulating variable C
9-1. If the dollar and blank
9-2. Timed input
9-3. Once again, timed input
9-4. Timed Read
9-5. Am I the root?
9-6. arglist: Listing arguments with $ * $ @
9-7. Inconsistent $ * and $ @ behavior
9-8. * USD USD USD @ When IFS is empty
9-9. Underline variable
9-10. Using declaration type variables
9-11. Generate random numbers
9-12. Pick a card from a deck of cards
9-13. Brownian motion Simulation
9-14. Random values
9-15. Single-Chip with random
9-16. Random of Replant
9-17. Pseudo-random number, using awk
10-1. Insert a blank line between paragraphs in a text file
10-2. Produces a random string of characters
10-3. Convert graphics file format, file name change
10-4. Convert audio file support
10-5. Simulation getopt
10-6. Alternative methods for extracting and locating substrings
10-7. Using parameter substitution and error messages
10-8. Parameter substitution and "use" messages
10-9. The length of the variable
10-10. Pattern matching in parameter substitution
10-11. To rename a file name extension:
10-12. Use pattern matching to parse arbitrary strings
10-13. The matching pattern of the prefix or suffix of a string
11-1. A simple loop
11-2. Loops with 2 parameters in each element
11-3. FileInfo: Manipulating variables contained in a file list
11-4. A parameterized file list operation
11-5. Use a loop to manipulate the file
11-6. Missing in [list]
11-7. generating [list] in a command substitution loop
11-8. Lookup substitution of a binary file
11-9. List all users in the system
11-10. Check the author of all binaries in a directory
11-11. List symbolic links in a directory
11-12. A symbolic link in a directory that is saved to a file
11-13. C-Ring
11-14. Using digital faxes in batch mode
11-15. Simple loop
11-16. Another loop
11-17. Multi-condition Loops
11-18. In a while loop syntax style
11-19. Cycle
11-20. Nested loops
11-21. The role of interruption and continuation in a cycle
11-22. Break the levels of multiple loops
11-23. Continue at a higher cycle level
11-24. Continue to use in actual tasks
11-25. Use case
11-26. Create a menu use case
11-27. To replace a build variable with a command
11-28. Simple string Matching
11-29. Check Pinyin input
11-30. Create a menu using the selection
11-31. Create a menu in a function using the
12-1. Stupid script.
12-2. Generate a variable from the loop
12-3. Find a crossword puzzle
15-1. A script that generates multiple instances of itself
15-2. printf in action
15-3. Variable assignment, using read
15-4. What happens when a variable is read
15-5. Multi-Line Input read
15-6. Detect arrow keys
7. Using Read file redirection
15-8. Reading from a pipe problem
15-9. Change the current working directory
15-10. Let's do the arithmetic.
15-11. Performance evaluation of the display
15-12. Use eval to select between variables
15-13. Echoing command-line arguments
15-14. Force logoff
15-15. A version of ROT13
15-16. Use position parameter settings
15-17. Reversing position Parameters
15-18. The specified positional parameters
15-19. "A immutable
15-20. Use egress to pass variables to an embedded awk script
15-21. Pass to script using getopts reading Options/Parameters
15-22. "Include" Data files
15-23. A (useless) script, the source itself
15-24. Impact execution
15-25. A script that executes itself
15. Wait for a process to finish before processing
15-27. A script that kills himself.
16-1. Creating catalogs with LS burning discs
16-2. Hello or goodbye
16-3. Badname, eliminating the file name of the current directory that contains characters and spaces is not good.
16-4. Delete the inode number of a file
16-5. Log files: Monitoring system logs with Xargs
16-6. Copy files from the current directory to another directory
16-7. Name of the killing process
16-8. Using Xargs Frequency analysis
16-9. Using an expression
16-10. Use Date
16-11. Date Calculation
16 wins 12. Word Frequency analysis
16-13. Which files are scripts?
16-14. Generate 10-bit random numbers
16-15. Use the tail to monitor the system log
16-16. Print out the rows stored in the e-mail message
16-17. Emulation grep in the script
16-18. Puzzle solving
16-19. Merriam-Webster Dictionary definition 1913
16-20. Check the validity of a word in a list
16-21. Up: Converts all files to uppercase.
16-22. Lowercase: Change all file names in the working directory to lowercase.
16-23. Du: Conversion of Dos to UNIX text files.
16-24. ROT13: Ultra-weak encryption.
16-25. Create a "password reference" puzzle
16-26. A list of formatted files.
16-27. Use columns to format a list of directories
16-28. NL: Self-numbering script.
16-29. Manview: Viewing formatted online
16-30. Use Cpio to move a directory tree
16-31. Open box rpm file
16-32. Stripping comments from a C + + program file
16-33. Explore/USR/X11R6/box
16-34. An "improved" string command
16-35. Compare two files using a CMP script.
16-36. BaseName and directories
18-37. A script that copies itself in the section
16-38. Check the integrity of the file
16-39. Uudecoding encoded files
16-40. Find out who is reporting spam senders
16-41. Junk Mail Domain analysis
1642. Get Stock Quote
16-43. Update FC4
16-44. Using SSH
16-45. Script for the message itself
16-46. Generating primes
16-47. Mortgage payments by Month
16-48. Base conversion
Admission. Use the file here in BC
16-50. Calculation
46. A decimal number is made into the
16~52. Factoring Business
16-53. Calculate the hypotenuse of a triangle
16~54. Generating loop parameters using SEQ
16-55. Letter Count
which Using getopt to parse command-line options
16-57. Copy your own script
16-58. Workout DD
16-59. Capturing keystrokes
16-60. Prepare a bootable Raspberry Pi SD card
16-61. Safely delete files
16~62. File name Generator
-63. Convert meters to Miles
64. With M4
17-1. Set a new password
17-2. Setting Erase Characters
17-3. Password: Close terminal echo
17-4. Key detection
17-5. Check IDENTD get remote server
17-6. Pidof Help Kill Process
17-7. Check the disc image
17-8. Creating a file system in a file
17-9. Add a new hard drive
17-10. Use Umask hide to spy on an output file
17-11. Backlight: Change (laptop) screen backlight brightness
17-12. Killall, from/ETC/RC. D d/Initialize.
19-1. Broadcast: Send a message to each logged-on person
19-2. Fake archives: Create a virtual file 2
19-3. Using multi-line information for Cats
19-4. Multi-line messages, with tab suppression
19-5. Document with replaceable parameters
19-6. Upload a file to the SunSITE incoming directory
197. Parameter substitution
Play. Script that produces another script
19-9. The files and features here
Expedient. "Anonymous" here file
19-11. Comment out code block
19-12. A self-documenting script
19-13. Add a line file in front of
19-14. Resolve Mailbox
20-1. REDIRECT stdin using exec
20-2. REDIRECT StdOut using exec
20-3. StdIn and stdout redirects are executed in the same script
20-4. Avoid shell layers
20-5. REDIRECT Loop
20-6. Alternating forms of loops
20-7. Redirect to Loop
20-8. REDIRECT Loop
20-9. Loops (including redirected stdin and stdout redirects)
20-10. If/and then test the redirect
20-11. The data file for the above example Names.data
20-12. Logging Events
21-1. Variable range in the first layer
2. User Profile List
21-3. Layers in parallel run process
22-1. Running scripts in restricted mode
23-1. Code block redirection not forked
23-2. The redirect process replaces the output into a circle.
24-1. Simple functions
2. function parameters
24-3. Functions and command line arguments passed to the script
24-4. Functions that are indirectly referenced
24-5. To pass a reference parameter to a function
24-6. Again, the reference parameter is passed to the function
24-7. Maximum Value
24-8. Convert numbers to Roman numerals
24-9. To test a large return value in a function
24-10. Compare large integers
24-11. Real Mingshi Name
24-12. Visibility of local variables
24-13. A demonstration of a simple recursive function
24-14. Another simple demo
24-15. Recursive, using local variables
Highest. Fibonacci sequence
24-17. Hanoi
25-1. Alias in a script
25-2. Unalias: Aliases for setting and resetting
26-1. Using and listing to test command-line arguments
26-2. Another command-line parameter test uses a list
26-30. Use or list combination to and list
27-1. Simple array Use
27-2. Format a Poem
27-3. Various array operations
27-4. string manipulation of arrays
27-5. Loading the contents of a script into an array
27-6. Some special properties of the array
27-7. Empty arrays and empty elements
27-8. Initializing an array
27-9. Copying and concatenating arrays
27-10. In a series array
27-11. Bubble sort
Currently, 27 wins and 12 losses are achieved. Embedded arrays and indirect references
27-13. Sieve method
27-14. Sieve method, optimize
27-15. Simulate a push-down stack
27-16. Complex Array application: Explore a strange series of mathematics
Section. Simulate a two-dimensional array and tilt it
28-1. Indirect variable Reference
28-2. by indirectly referencing awk
29-1. Use/dev/tcp Troubleshooting
29-2. Playing music
29-3. Looking for a process with a control
29. Online Connection Status
30-1. Print server environment
30-2. Address
31-1. Stash Cookie Jar
31-2. Create a swap file using/dev/zero
31-3. Create a virtual disk
32-1. The script of the carriage
32-2. Missing keywords
Can Test script: Another car
32-4. Test a condition with an assertion
32-5. At the exit point
32-6. After cleaning, control
32-7. A simple execution progress bar
32-8. Tracking variables
32-9. Run multiple processes (in an SMP box)
34-1. Numeric and string comparisons are not equivalent
34-2. Electronic traps
34-3. echo reading of pipe output
36-1. Shell Wrapper
36-2. A more complex shell wrapper
36-3. A generic shell wrapper that writes to the log file
36-4. In an awk script shell wrapper
36-5. In another awk script shell wrapper
36-6. Embed a bash script in Perl
36-7. Combination of bash and Perl scripts
36-8. Python embeds a bash script
36-9. The script of the speech
36-10. A (useless) script that is called recursively
36-11. A (useful) script for recursive invocation
36-12. Another (useful) script for recursive invocation
36-13. "Color" Address database
36-14. Draw a Box
36-15. echo Color text
36-16. The game of "horse racing"
36-17. A progress bar
36-18. The trick of returning a value
36-19. More tricks to return the value
36-20. Passing and returning arrays
36-21. Funny crossword puzzles.
36-22. Widgets called from the shell script
36-23. Test suite
37-1. String extension
37-2. Indirect variable reference-new method
37-3. Simple database application that uses indirect variable references
37-4 years. Use arrays and other frauds to create four random hands
37-5. A simple address database
37-6. More complex address databases
37-7. Test character
37-8. Reading characters
37-9. Use here to set variables
37-10. Pipe input Read
37-11. Negative array indicator
37-12. Negative parameters in string extraction constructs
A-1. MailFormat: E-mail in format
A-2. Bean: A simple-minded file renaming tool
A-3. Rename: Rename a blank that contains spaces in the file name
A-4. ENCRYPTEDPW: Upload to FTP site with locally encrypted password
A-5. Copying discs: Copying data discs
A-6. Collatz Series
A-7. Days between: Days of the date
A-8. Make a dictionary
A-9. Detection method Conversion
A-10. Life Games
A-11. Data files for Life games
A-12. Slash: Deleted messages and news message headers
13. Password: Generates a random 8-character password
A-14. FIFO: daily backup, using Named pipes
A-15. Generating prime numbers using modulo operators
48. Tree: Displaying a directory tree
A-17. Tree2: Script for alternate directory tree
A-18. String functions: C-style String functions
A-19. Directory information
20. hash function Library
21st. Coloring text using the hash function
22. More about hashing functions
A 23. Installing a USB Keychain storage device
A-24. Convert to HTML
A-25. Keep your blog
26. Protect string
A-27. Decrypting a string
A-28. Junk e-mail identification
A-29. Junk Mail Hunt
A-30. Make wget easier to use
31. A podcast script
A-32. Nightly Backup to FireWire HD
A-33. Extended Disc Command
A-34. Sound card installation Script
A-35. To position a split paragraph in a text file
Use. Insert Sort
A-37. Standard deviation
A-38. To the shareware author pad file Generator
A-39. A Web page Editor
A-40. Rose Petals
A-41. Quacky: A perquackey type of Word game
A-42. Nim
A-43. Command line
A-44. A common shell scripting job scenario
A-45. Knight's Tour
A-46. Magic Square
A-47. XV Puzzle
A-48. Tower of Hanoi, graphic version
A-49. Hanoi's tower, alternating graphic version
A-50. Another version of the getopt-simple.sh script
A-51. Version usegetopt.sh instance appendix for label Extensions
Protein A52. Cycle through all possible color backgrounds
a-53. The practice of Morse code
a-54. BASE64 encoding/decoding
A-55. Using sed in inserting text files
a-56. The Gronsfeld password
Ann-57. Digital generators
a-58. Basic knowledge
A-59. Test execution time for various commands
A-60. Associative arrays vs. legacy arrays (Execution time)
C-1. The advent of counting letters
J-1. Complete the script for usegetopt.sh
M-1. BASHRC file Sample.
M-2. Bash_profile file.
N-1. Viewdata.bat:DOS Batch processing files
N-2. Viewdata.sh:viewdata.bat Shell Script Conversions
T-1. A script that generates an ASCII table
T-2. Another ASCII table script
T-3. One-third ASCII table scripts, using awk
Advanced Bash Scripting Programming Guide