Advanced Bash-Scripting Guide

本文档详尽地介绍了Bash脚本编程的基础到高级主题,包括变量处理、流程控制、函数使用、输入输出重定向等核心概念和技术,并提供了丰富的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面的内容摘自http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/index.html,方便查看

Dedication

For Anita, the source of all the magic

Table of Contents Part 1. Introduction
1. Why Shell Programming?
2. Starting Off With a Sha-Bang
Part 2. Basics
3. Special Characters
4. Introduction to Variables and Parameters
5. Quoting
6. Exit and Exit Status
7. Tests
8. Operations and Related Topics
Part 3. Beyond the Basics
9. Variables Revisited
10. Loops and Branches
11. Internal Commands and Builtins
12. External Filters, Programs and Commands
13. System and Administrative Commands
14. Command Substitution
15. Arithmetic Expansion
16. I/O Redirection
17. Here Documents
18. Recess Time
Part 4. Advanced Topics
19. Regular Expressions
20. Subshells
21. Restricted Shells
22. Process Substitution
23. Functions
24. Aliases
25. List Constructs
26. Arrays
27. /dev and /proc
28. Of Zeros and Nulls
29. Debugging
30. Options
31. Gotchas
32. Scripting With Style
33. Miscellany
34. Bash, versions 2 and 3
35. Endnotes
35.1. Author's Note
35.2. About the Author
35.3. Where to Go For Help
35.4. Tools Used to Produce This Book
35.5. Credits
Bibliography
A. Contributed Scripts
B. Reference Cards
C. A Sed and Awk Micro-Primer
C.1. Sed
C.2. Awk
D. Exit Codes With Special Meanings
E. A Detailed Introduction to I/O and I/O Redirection
F. Standard Command-Line Options
G. Important Files
H. Important System Directories
I. Localization
J. History Commands
K. A Sample .bashrc File
L. Converting DOS Batch Files to Shell Scripts
M. Exercises
M.1. Analyzing Scripts
M.2. Writing Scripts
N. Revision History
O. Mirror Sites
P. To Do List
Q. Copyright
List of Examples 2-1. cleanup: A script to clean up the log files in /var/log
2-2. cleanup: An improved clean-up script
2-3. cleanup: An enhanced and generalized version of above scripts.
3-1. Code blocks and I/O redirection
3-2. Saving the results of a code block to a file
3-3. Running a loop in the background
3-4. Backup of all files changed in last day
4-1. Variable assignment and substitution
4-2. Plain Variable Assignment
4-3. Variable Assignment, plain and fancy
4-4. Integer or string?
4-5. Positional Parameters
4-6. wh, whois
4-7. Using shift
5-1. Echoing Weird Variables
5-2. Escaped Characters
6-1. exit / exit status
6-2. Negating a condition using !
7-1. What is truth?
7-2. Equivalence of test, /usr/bin/test, [ ], and /usr/bin/[
7-3. Arithmetic Tests using (( ))
7-4. Testing for broken links
7-5. Arithmetic and string comparisons
7-6. Testing whether a string is null
7-7. zmore
8-1. Greatest common divisor
8-2. Using Arithmetic Operations
8-3. Compound Condition Tests Using && and ||
8-4. Representation of numerical constants
9-1. $IFS and whitespace
9-2. Timed Input
9-3. Once more, timed input
9-4. Timed read
9-5. Am I root?
9-6. arglist: Listing arguments with $* and $@
9-7. Inconsistent $* and $@ behavior
9-8. $* and $@ when $IFS is empty
9-9. Underscore variable
9-10. Inserting a blank line between paragraphs in a text file
9-11. Converting graphic file formats, with filename change
9-12. Emulating getopt
9-13. Alternate ways of extracting substrings
9-14. Using parameter substitution and error messages
9-15. Parameter substitution and "usage" messages
9-16. Length of a variable
9-17. Pattern matching in parameter substitution
9-18. Renaming file extensions:
9-19. Using pattern matching to parse arbitrary strings
9-20. Matching patterns at prefix or suffix of string
9-21. Using declare to type variables
9-22. Indirect References
9-23. Passing an indirect reference to awk
9-24. Generating random numbers
9-25. Picking a random card from a deck
9-26. Random between values
9-27. Rolling a single die with RANDOM
9-28. Reseeding RANDOM
9-29. Pseudorandom numbers, using awk
9-30. C-type manipulation of variables
10-1. Simple for loops
10-2. for loop with two parameters in each [list] element
10-3. Fileinfo: operating on a file list contained in a variable
10-4. Operating on files with a for loop
10-5. Missing in [list] in a for loop
10-6. Generating the [list] in a for loop with command substitution
10-7. A grep
10-8. Listing all users on the system
10-9. Checking all the binaries in a directory for authorship
10-10. Listing the symbolic links
10-11. Symbolic links in a directory, saved to a file
10-12. A C-like for loop
10-13. Using efax in batch mode
10-14. Simple while loop
10-15. Another while loop
10-16. while loop with multiple conditions
10-17. C-like syntax in a while loop
10-18. until loop
10-19. Nested Loop
10-20. Effects of break and continue in a loop
10-21. Breaking out of multiple loop levels
10-22. Continuing at a higher loop level
10-23. Using "continue N" in an actual task
10-24. Using case
10-25. Creating menus using case
10-26. Using command substitution to generate the case variable
10-27. Simple string matching
10-28. Checking for alphabetic input
10-29. Creating menus using select
10-30. Creating menus using select in a function
11-1. A script that forks off multiple instances of itself
11-2. printf in action
11-3. Variable assignment, using read
11-4. What happens when read has no variable
11-5. Multi-line input to read
11-6. Detecting the arrow keys
11-7. Using read with file redirection
11-8. Problems reading from a pipe
11-9. Changing the current working directory
11-10. Letting "let" do arithmetic.
11-11. Showing the effect of eval
11-12. Forcing a log-off
11-13. A version of "rot13"
11-14. Using eval to force variable substitution in a Perl script
11-15. Using set with positional parameters
11-16. Reassigning the positional parameters
11-17. "Unsetting" a variable
11-18. Using export to pass a variable to an embedded awk
11-19. Using getopts to read the options/arguments passed to a script
11-20. "Including" a data file
11-21. A (useless) script that sources itself
11-22. Effects of exec
11-23. A script that exec's itself
11-24. Waiting for a process to finish before proceeding
11-25. A script that kills itself
12-1. Using ls to create a table of contents for burning a CDR disk
12-2. Hello or Good-bye
12-3. Badname, eliminate file names in current directory containing bad characters and whitespace. 12-4. Deleting a file by its inode number
12-5. Logfile: Using xargs to monitor system log
12-6. Copying files in current directory to another
12-7. Killing processes by name
12-8. Word frequency analysis using xargs
12-9. Using expr
12-10. Using date
12-11. Word Frequency Analysis
12-12. Which files are scripts?
12-13. Generating 10-digit random numbers
12-14. Using tail to monitor the system log
12-15. Emulating "grep" in a script
12-16. Looking up definitions in Webster's 1913 Dictionary
12-17. Checking words in a list for validity
12-18. toupper: Transforms a file to all uppercase.
12-19. lowercase: Changes all filenames in working directory to lowercase.
12-20. Du: DOS to UNIX text file conversion.
12-21. rot13: rot13, ultra-weak encryption.
12-22. Generating "Crypto-Quote" Puzzles
12-23. Formatted file listing.
12-24. Using column to format a directory listing
12-25. nl: A self-numbering script.
12-26. manview: Viewing formatted manpages
12-27. Using cpio to move a directory tree
12-28. Unpacking an rpm archive
12-29. Stripping comments from C program files
12-30. Exploring /usr/X11R6/bin
12-31. An "improved" strings command
12-32. Using cmp to compare two files within a script.
12-33. basename and dirname
12-34. Checking file integrity
12-35. Uudecoding encoded files
12-36. Finding out where to report a spammer
12-37. Analyzing a spam domain
12-38. Getting a stock quote
12-39. Updating FC4
12-40. Using ssh
12-41. A script that mails itself
12-42. Monthly Payment on a Mortgage
12-43. Base Conversion
12-44. Invoking bc using a "here document"
12-45. Calculating PI
12-46. Converting a decimal number to hexadecimal
12-47. Factoring
12-48. Calculating the hypotenuse of a triangle
12-49. Using seq to generate loop arguments
12-50. Letter Count"
12-51. Using getopt to parse command-line options
12-52. A script that copies itself
12-53. Exercising dd
12-54. Capturing Keystrokes
12-55. Securely deleting a file
12-56. Filename generator
12-57. Converting meters to miles
12-58. Using m4
13-1. Setting a new password
13-2. Setting an erase character
13-3. secret password: Turning off terminal echoing
13-4. Keypress detection
13-5. Checking a remote server for identd
13-6. pidof helps kill a process
13-7. Checking a CD image
13-8. Creating a filesystem in a file
13-9. Adding a new hard drive
13-10. Using umask to hide an output file from prying eyes
13-11. killall, from /etc/rc.d/init.d
14-1. Stupid script tricks
14-2. Generating a variable from a loop
14-3. Finding anagrams
16-1. Redirecting stdin using exec
16-2. Redirecting stdout using exec
16-3. Redirecting both stdin and stdout in the same script with exec
16-4. Avoiding a subshell
16-5. Redirected while loop
16-6. Alternate form of redirected while loop
16-7. Redirected until loop
16-8. Redirected for loop
16-9. Redirected for loop (both stdin and stdout redirected)
16-10. Redirected if/then test
16-11. Data file "names.data" for above examples
16-12. Logging events
17-1. broadcast: Sends message to everyone logged in
17-2. dummyfile: Creates a 2-line dummy file
17-3. Multi-line message using cat
17-4. Multi-line message, with tabs suppressed
17-5. Here document with parameter substitution
17-6. Upload a file pair to "Sunsite" incoming directory
17-7. Parameter substitution turned off
17-8. A script that generates another script
17-9. Here documents and functions
17-10. "Anonymous" Here Document
17-11. Commenting out a block of code
17-12. A self-documenting script
17-13. Prepending a line to a file
20-1. Variable scope in a subshell
20-2. List User Profiles
20-3. Running parallel processes in subshells
21-1. Running a script in restricted mode
23-1. Simple functions
23-2. Function Taking Parameters
23-3. Functions and command-line args passed to the script
23-4. Passing an indirect reference to a function
23-5. Dereferencing a parameter passed to a function
23-6. Again, dereferencing a parameter passed to a function
23-7. Maximum of two numbers
23-8. Converting numbers to Roman numerals
23-9. Testing large return values in a function
23-10. Comparing two large integers
23-11. Real name from username
23-12. Local variable visibility
23-13. Recursion, using a local variable
23-14. The Towers of Hanoi
24-1. Aliases within a script
24-2. unalias: Setting and unsetting an alias
25-1. Using an "and list" to test for command-line arguments
25-2. Another command-line arg test using an "and list"
25-3. Using "or lists" in combination with an "and list"
26-1. Simple array usage
26-2. Formatting a poem
26-3. Various array operations
26-4. String operations on arrays
26-5. Loading the contents of a script into an array
26-6. Some special properties of arrays
26-7. Of empty arrays and empty elements
26-8. Initializing arrays
26-9. Copying and concatenating arrays
26-10. More on concatenating arrays
26-11. An old friend: The Bubble Sort
26-12. Embedded arrays and indirect references
26-13. Complex array application: Sieve of Eratosthenes
26-14. Emulating a push-down stack
26-15. Complex array application: Exploring a weird mathematical series
26-16. Simulating a two-dimensional array, then tilting it
27-1. Using /dev/tcp for troubleshooting
27-2. Finding the process associated with a PID
27-3. On-line connect status
28-1. Hiding the cookie jar
28-2. Setting up a swapfile using /dev/zero
28-3. Creating a ramdisk
29-1. A buggy script
29-2. Missing keyword
29-3. test24, another buggy script
29-4. Testing a condition with an "assert"
29-5. Trapping at exit
29-6. Cleaning up after Control-C
29-7. Tracing a variable
29-8. Running multiple processes (on an SMP box)
31-1. Numerical and string comparison are not equivalent
31-2. Subshell Pitfalls
31-3. Piping the output of echo to a read
33-1. shell wrapper
33-2. A slightly more complex shell wrapper
33-3. A generic shell wrapper that writes to a logfile
33-4. A shell wrapper around an awk script
33-5. A shell wrapper around another awk script
33-6. Perl embedded in a Bash script
33-7. Bash and Perl scripts combined
33-8. A (useless) script that recursively calls itself
33-9. A (useful) script that recursively calls itself
33-10. Another (useful) script that recursively calls itself
33-11. A "colorized" address database
33-12. Drawing a box
33-13. Echoing colored text
33-14. A "horserace" game
33-15. Return value trickery
33-16. Even more return value trickery
33-17. Passing and returning arrays
33-18. Fun with anagrams
33-19. Widgets invoked from a shell script
34-1. String expansion
34-2. Indirect variable references - the new way
34-3. Simple database application, using indirect variable referencing
34-4. Using arrays and other miscellaneous trickery to deal four random hands from a deck of cards
A-1. mailformat: Formatting an e-mail message
A-2. rn: A simple-minded file rename utility
A-3. blank-rename: renames filenames containing blanks
A-4. encryptedpw: Uploading to an ftp site, using a locally encrypted password
A-5. copy-cd: Copying a data CD
A-6. Collatz series
A-7. days-between: Calculate number of days between two dates
A-8. Make a "dictionary"
A-9. Soundex conversion
A-10. "Game of Life"
A-11. Data file for "Game of Life"
A-12. behead: Removing mail and news message headers
A-13. ftpget: Downloading files via ftp
A-14. password: Generating random 8-character passwords
A-15. fifo: Making daily backups, using named pipes
A-16. Generating prime numbers using the modulo operator
A-17. tree: Displaying a directory tree
A-18. string functions: C-like string functions
A-19. Directory information
A-20. Object-oriented database
A-21. Library of hash functions
A-22. Colorizing text using hash functions
A-23. Mounting USB keychain storage devices
A-24. Preserving weblogs
A-25. Protecting literal strings
A-26. Unprotecting literal strings
A-27. Spammer Identification
A-28. Spammer Hunt
A-29. Making wget easier to use
A-30. A "podcasting" script
A-31. Basics Reviewed
A-32. An expanded cd command
C-1. Counting Letter Occurrences
K-1. Sample .bashrc file
L-1. VIEWDATA.BAT: DOS Batch File
L-2. viewdata.sh: Shell Script Conversion of VIEWDATA.BAT
P-1. Print the server environment
目录 ++++ 第一部分. 热身 1. 为什么使用shell 编程 2. 带着一个Sha-Bang 出发(Sha-Bang 指的是#!) 2.1. 调用一个脚本 2.2. 初步的练习 第二部分. 基本 3. 特殊字符 4. 变量和参数的介绍 4.1. 变量替换 4.2. 变量赋值 4.3. Bash 变量是不分类型的 4.4. 特殊的变量类型 5. 引用(翻译的可能有问题,特指引号) 5.1. 引用变量 5.2. 转义(\) 6. 退出和退出状态 7. Tests 7.1. Test 结构 7.2. 文件测试操作 7.3. 其他比较操作 7.4. 嵌套的if/then 条件test 7.5. 检查你的test 知识 8. 操作符和相关的主题 8.1. 操作符 8.2. 数字常量 第三部分. 超越基本 9. 变量重游 9.1. 内部变量 9.2. 操作字符串 9.3. 参数替换 9.4. 指定类型的变量:declare 或者typeset 9.5. 变量的间接引用 9.6. $RANDOM: 产生随机整数 9.7. 双圆括号结构 10. 循环和分支 10.1. 循环 10.2. 嵌套循环 10.3. 循环控制 10.4. 测试与分支(case 和select 结构) 11. 内部命令与内建 11.1. 作业控制命令 12. 外部过滤器,程序和命令 12.1. 基本命令 12.2. 复杂命令 12.3. 时间/日期 命令 12.4. 文本处理命令 12.5. 文件与归档命令 12.6. 通讯命令 12.7. 终端控制命令 12.8. 数学计算命令 12.9. 混杂命令 13. 系统与管理命令 13.1. 分析一个系统脚本 14. 命令替换 15. 算术扩展 16. I/O 重定向 16.1. 使用exec 16.2. 代码块的重定向 16.3. 应用 17. Here Documents 17.1. Here Strings 18. 休息时间 Part 4. 高级 19. 正则表达式 19.1. 一个简要的正则表达式介绍 19.2. 通配 20. 子shell(Subshells) 21. 受限shell(Restricted Shells) 22. 进程替换 23. 函数 23.1. 复杂函数和函数复杂性 23.2. 局部变量 23.3. 不使用局部变量的递归 24. 别名(Aliases) 25. 列表结构 26. 数组 27. /dev 和 /proc 27.1. /dev 27.2. /proc 28. 关于Zeros 和Nulls 29. 调试 30. 选项 31. Gotchas 32. 脚本编程风格 32.1. 非官方的Shell 脚本风格 33. 杂项 33.1. 交互式和非交互式的shells 和脚本 33.2. Shell 包装 33.3. 测试和比较: 另一种方法 33.4. 递归 33.5. 彩色脚本 33.6. 优化 33.7. 各种小技巧 33.8. 安全话题 33.8.1. 被感染的脚本 33.8.2. 隐藏Shell 脚本源码 33.9. 移植话题 33.10. 在Windows 下进行Shell 编程 34. Bash, 版本 2 和 3 34.1. Bash, 版本2 34.2. Bash, 版本3 35. 后记 35.1. 作者后记 35.2. 关于作者 35.3. 哪里可以取得帮助? 35.4. 制作这本书的工具 35.4.1. 硬件 35.4.2. 软件和排版软件 35.5. Credits Bibliography A. Contributed Scripts B. Reference Cards C. A Sed and Awk Micro-Primer C.1. Sed C.2. Awk D. Exit Codes With Special Meanings E. A Detailed Introduction to I/O and I/O Redirection F. Standard Command-Line Options G. Important Files H. Important System Directories I. Localization J. History Commands K. A Sample .bashrc File L. Converting DOS Batch Files to Shell Scripts M. Exercises M.1. Analyzing Scripts M.2. Writing Scripts N. Revision History O. Mirror Sites P. To Do List Q. Copyright 表格清单: 11-1. 作业标识符 30-1. Bash 选项 33-1. 转义序列中数值和彩色的对应 B-1. Special Shell Variables B-2. TEST Operators: Binary Comparison B-3. TEST Operators: Files B-4. Parameter Substitution and Expansion B-5. String Operations B-6. Miscellaneous Constructs C-1. Basic sed operators C-2. Examples of sed operators D-1. "Reserved" Exit Codes L-1. Batch file keywords / variables / operators, and their shell equivalents L-2. DOS commands and their UNIX equivalents N-1. Revision History 例子清单: 2-1. 清除:清除/var/log 下的log 文件 2-2. 清除:一个改良的清除脚本 2-3. cleanup:一个增强的和广义的删除logfile 的脚本 3-1. 代码块和I/O 重定向 3-2. 将一个代码块的结果保存到文件 3-3. 在后台运行一个循环 3-4. 备份最后一天所有修改的文件. 4-1. 变量赋值和替换 4-2. 一般的变量赋值 4-3. 变量赋值,一般的和比较特殊的 4-4. 整型还是string? 4-5. 位置参数 4-6. wh,whois 节点名字查询 4-7. 使用shift 5-1. echo 一些诡异的变量 5-2. 转义符 6-1. exit/exit 状态 6-2. 否定一个条件使用! 7-1. 什么情况下为真? 7-2. 几个等效命令test,/usr/bin/test,[],和/usr/bin/[ 7-3. 算数测试使用(( )) 7-4. test 死的链接文件 7-5. 数字和字符串比较 7-6. 测试字符串是否为null 7-7. zmore 8-1. 最大公约数 8-2. 使用算术操作符 8-3. 使用&&和||进行混合状态的test 8-4. 数字常量的处理 9-1. $IFS 和空白 9-2. 时间输入 9-3. 再来一个时间输入 9-4. Timed read 9-5. 我是root? 9-6. arglist:通过$*和$@列出所有的参数 9-7. 不一致的$*和$@行为 9-8. 当$IFS 为空时的$*和$@ 9-9. 下划线变量 9-10. 在一个文本文件的段间插入空行 9-11. 利用修改文件名,来转换图片格式 9-12. 模仿getopt 命令 9-13. 提取字符串的一种可选的方法 9-14. 使用参数替换和error messages 9-15. 参数替换和"usage"messages 9-16. 变量长度 9-17. 参数替换中的模式匹配 9-18. 重命名文件扩展名 9-19. 使用模式匹配来分析比较特殊的字符串 9-20. 对字符串的前缀或后缀使用匹配模式 9-21. 使用declare 来指定变量的类型 9-22. 间接引用 9-23. 传递一个间接引用给awk 9-24. 产生随机数 9-25. 从一副扑克牌中取出一张随机的牌 9-26. 两个指定值之间的随机数 9-27. 使用随机数来摇一个骰子 9-28. 重新分配随机数种子 9-29. 使用awk 产生伪随机数 9-30. C 风格的变量处理 10-1. 循环的一个简单例子 10-2. 每个[list]元素带两个参数的for 循环 10-3. 文件信息:对包含在变量中的文件列表进行操作 10-4. 在for 循环中操作文件 10-5. 在for 循环中省略[list] 10-6. 使用命令替换来产生for 循环的[list] 10-7. 对于二进制文件的一个grep 替换 10-8. 列出系统上的所有用户 10-9. 在目录的所有文件中查找源字串 10-10. 列出目录中所有的符号连接文件 10-11. 将目录中的符号连接文件名保存到一个文件中 10-12. 一个C 风格的for 循环 10-13. 在batch mode 中使用efax 10-14. 简单的while 循环 10-15. 另一个while 循环 10-16. 多条件的while 循环 10-17. C 风格的while 循环 10-18. until 循环 10-19. 嵌套循环 10-20. break 和continue 命令在循环中的效果 10-21. 多层循环的退出 10-22. 多层循环的continue 10-23. 在实际的任务中使用"continue N" 10-24. 使用case 10-25. 使用case 来创建菜单 10-26. 使用命令替换来产生case 变量 10-27. 简单字符串匹配 10-28. 检查是否是字母输入 10-29. 用select 来创建菜单 10-30. 用函数中select 结构来创建菜单 11-1. 一个fork 出多个自己实例的脚本 11-2. printf 11-3. 使用read,变量分配 11-4. 当使用一个不带变量参数的read 命令时,将会发生什么? 11-5. read 命令的多行输入 11-6. 检测方向键 11-7. 通过文件重定向来使用read 11-8. 管道输出到read 中的问题 11-9. 修改当前的工作目录 11-10. 用"let"命令来作算术操作. 11-11. 显示eval 命令的效果 11-12. 强制登出(log-off) 11-13. 另一个"rot13"的版本 11-14. 在Perl 脚本中使用eval 命令来强制变量替换 11-15. 使用set 来改变脚本的位置参数 11-16. 重新分配位置参数 11-17. Unset 一个变量 11-18. 使用export 命令传递一个变量到一个内嵌awk 的脚本中 11-19. 使用getopts 命令来读取传递给脚本的选项/参数. 11-20. "Including"一个数据文件 11-21. 一个没什么用的,source 自身的脚本 11-22. exec 的效果 11-23. 一个exec 自身的脚本 11-24. 在继续处理之前,等待一个进程的结束 11-25. 一个结束自身的脚本. 12-1. 使用ls 命令来创建一个烧录CDR 的内容列表 12-2. Hello or Good-bye 12-3. 删除当前目录下文件名中包含一些特殊字符(包括空白)的文件.. 12-4. 通过文件的 inode 号来删除文件 12-5. Logfile: 使用 xargs 来监控系统 log 12-6. 把当前目录下的文件拷贝到另一个文件中 12-7. 通过名字Kill 进程 12-8. 使用xargs 分析单词出现的频率 12-9. 使用 expr 12-10. 使用 date 命令 12-11. 分析单词出现的频率 12-12. 那个文件是脚本? 12-13. 产生10 进制随机数 12-14. 使用 tail 命令来监控系统log 12-15. 在一个脚本中模仿 "grep" 的行为 12-16. 在1913 年的韦氏词典中查找定义 12-17. 检查列表中单词的正确性 12-18. 转换大写: 把一个文件的内容全部转换为大写. 12-19. 转换小写: 将当前目录下的所有文全部转换为小写. 12-20. Du: DOS 到 UNIX 文本文件的转换. 12-21. rot13: rot13, 弱智加密. 12-22. Generating "Crypto-Quote" Puzzles 12-23. 格式化文件列表. 12-24. 使用 column 来格式化目录列表 12-25. nl: 一个自己计算行号的脚本. 12-26. manview: 查看格式化的man 页 12-27. 使用 cpio 来拷贝一个目录树 12-28. 解包一个 rpm 归档文件 12-29. 从 C 文件中去掉注释 12-30. Exploring /usr/X11R6/bin 12-31. 一个"改进过"的 strings 命令 12-32. 在一个脚本中使用 cmp 来比较2 个文件. 12-33. basename 和 dirname 12-34. 检查文件完整性 12-35. Uudecod 编码后的文件 12-36. 查找滥用的连接来报告垃圾邮件发送者 12-37. 分析一个垃圾邮件域 12-38. 获得一份股票报价 12-39. 更新 Fedora Core 4 12-40. 使用 ssh 12-41. 一个可以mail 自己的脚本 12-42. 按月偿还贷款 12-43. 数制转换 12-44. 使用 "here document" 来调用 bc 12-45. 计算圆周率 12-46. 将10 进制数字转换为16 进制数字 12-47. 因子分解 12-48. 计算直角三角形的斜边 12-49. 使用 seq 来产生循环参数 12-50. 字母统计 12-51. 使用getopt 来分析命令行选项 12-52. 一个拷贝自身的脚本 12-53. 练习dd 12-54. 记录按键 12-55. 安全的删除一个文件 12-56. 文件名产生器 12-57. 将米转换为英里 12-58. 使用 m4 13-1. 设置一个新密码 13-2. 设置一个擦除字符 13-3. 关掉终端对于密码的echo 13-4. 按键检测 13-5. Checking a remote server for identd 13-6. pidof 帮助杀掉一个进程 13-7. 检查一个CD 镜像 13-8. 在一个文件中创建文件系统 13-9. 添加一个新的硬盘驱动器 13-10. 使用umask 来将输出文件隐藏起来 13-11. killall, 来自于 /etc/rc.d/init.d 14-1. 愚蠢的脚本策略 14-2. 从循环的输出中产生一个变量 14-3. 找anagram(回文构词法, 可以将一个有意义的单词, 变换为1 个或多个有意义的单词, 但 是还是原来的子母集合) 16-1. 使用exec 重定向标准输入 16-2. 使用exec 来重定向stdout 16-3. 使用exec 在同一脚本中重定向stdin 和stdout 16-4. 避免子shell 16-5. while 循环的重定向 16-6. 另一种while 循环的重定向 16-7. until 循环重定向 16-8. for 循环重定向 16-9. for 循环重定向 loop (将标准输入和标准输出都重定向了) 16-10. 重定向if/then 测试结构 16-11. 用于上面例子的"names.data"数据文件 16-12. 记录日志事件 17-1. 广播: 发送消息给每个登录上的用户 17-2. 仿造文件: 创建一个两行的仿造文件 17-3. 使用cat 的多行消息 17-4. 带有抑制tab 功能的多行消息 17-5. 使用参数替换的here document 17-6. 上传一个文件对到"Sunsite"的incoming 目录 17-7. 关闭参数替换 17-8. 一个产生另外一个脚本的脚本 17-9. Here documents 与函数 17-10. "匿名" here Document 17-11. 注释掉一段代码块 17-12. 一个自文档化(self-documenting)的脚本 17-13. 在一个文件的开头添加文本 20-1. 子shell 中的变量作用域 20-2. 列出用户的配置文件 20-3. 在子shell 里进行串行处理 21-1. 在受限的情况下运行脚本 23-1. 简单函数 23-2. 带着参数的函数 23-3. 函数和被传给脚本的命令行参数 23-4. 传递间接引用给函数 23-5. 解除传递给函数的参数引用 23-6. 再次尝试解除传递给函数的参数引用 23-7. 两个数中的最大者 23-8. 把数字转化成罗马数字 23-9. 测试函数最大的返回值 23-10. 比较两个大整数 23-11. 用户名的真实名 23-12. 局部变量的可见范围 23-13. 用局部变量来递归 23-14. 汉诺塔 24-1. 脚本中的别名 24-2. unalias: 设置和删除别名 25-1. 使用"与列表(and list)"来测试命令行参数 25-2. 用"与列表"的另一个命令行参数测试 25-3. "或列表"和"与列表"的结合使用 26-1. 简单的数组用法 26-2. 格式化一首诗 26-3. 多种数组操作 26-4. 用于数组的字符串操作符 26-5. 将脚本的内容传给数组 26-6. 一些数组专用的工具 26-7. 关于空数组和空数组元素 26-8. 初始化数组 26-9. 复制和连接数组 26-10. 关于连接数组的更多信息 26-11. 一位老朋友: 冒泡排序 26-12. 内嵌数组和间接引用 26-13. 复杂数组应用: 埃拉托色尼素数筛子 26-14. 模拟下推的堆栈 26-15. 复杂的数组应用: 列出一种怪异的数学序列 26-16. 模拟二维数组,并使它倾斜 27-1. 利用/dev/tcp 来检修故障 27-2. 搜索与一个PID 相关的进程 27-3. 网络连接状态 28-1. 隐藏cookie 而不再使用 28-2. 用/dev/zero 创建一个交换临时文件 28-3. 创建ramdisk 29-1. 一个错误的脚本 29-2. 丢失关键字(keyword) 29-3. 另一个错误脚本 29-4. 用"assert"测试条件 29-5. 捕捉 exit 29-6. 在Control-C 后清除垃圾 29-7. 跟踪变量 29-8. 运行多进程 (在多处理器的机器里) 31-1. 数字和字符串比较是不相等同的 31-2. 子SHELL 缺陷 31-3. 把echo 的输出用管道输送给read 命令 33-1. shell 包装 33-2. 稍微复杂一些的shell 包装 33-3. 写到日志文件的shell 包装 33-4. 包装awk 的脚本 33-5. 另一个包装awk 的脚本 33-6. 把Perl 嵌入Bash 脚本 33-7. Bash 和 Perl 脚本联合使用 33-8. 递归调用自己本身的(无用)脚本 33-9. 递归调用自己本身的(有用)脚本 33-10. 另一个递归调用自己本身的(有用)脚本 33-11. 一个 "彩色的" 地址资料库 33-12. 画盒子 33-13. 显示彩色文本 33-14. "赛马" 游戏 33-15. 返回值技巧 33-16. 整型还是string? 33-17. 传递和返回数组 33-18. anagrams 游戏 33-19. 在shell 脚本中调用的窗口部件 34-1. 字符串扩展 34-2. 间接变量引用 - 新方法 34-3. 使用间接变量引用的简单数据库应用 34-4. 用数组和其他的小技巧来处理四人随机打牌 A-1. mailformat: Formatting an e-mail message A-2. rn: A simple-minded file rename utility A-3. blank-rename: renames filenames containing blanks A-4. encryptedpw: Uploading to an ftp site, using a locally encrypted password A-5. copy-cd: Copying a data CD A-6. Collatz series A-7. days-between: Calculate number of days between two dates A-8. Make a "dictionary" A-9. Soundex conversion A-10. "Game of Life" A-11. Data file for "Game of Life" A-12. behead: Removing mail and news message headers A-13. ftpget: Downloading files via ftp A-14. password: Generating random 8-character passwords A-15. fifo: Making daily backups, using named pipes A-16. Generating prime numbers using the modulo operator A-17. tree: Displaying a directory tree A-18. string functions: C-like string functions A-19. Directory information A-20. Object-oriented database A-21. Library of hash functions A-22. Colorizing text using hash functions A-23. Mounting USB keychain storage devices A-24. Preserving weblogs A-25. Protecting literal strings A-26. Unprotecting literal strings A-27. Spammer Identification A-28. Spammer Hunt A-29. Making wget easier to use A-30. A "podcasting" script A-31. Basics Reviewed A-32. An expanded cd command C-1. Counting Letter Occurrences K-1. Sample .bashrc file L-1. VIEWDATA.BAT: DOS Batch File L-2. viewdata.sh: Shell Script Conversion of VIEWDATA.BAT P-1. Print the server environment
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值