记住:在写脚本的时候,在和脚本合并之前要一步一步测试每个步骤。
建立一个脚本Create a script that will take a (recursive) copy of files in /etc
so that a beginning system administrator can edit files without fear.
Write a script that takes exactly one argument, a directory name. If the number of arguments is more or less than one, print a usage message. If the argument is not a directory, print another message. For the given directory, print the five biggest files and the five files that were most recently modified.
Can you explain why it is so important to put the variables in between double quotes in the example from 第 9.4.2 节 “输出重定向”?
Write a script similar to the one in 第 9.5.1 节 “break 内建命令”, but think of a way of quitting after the user has executed 3 loops.
Think of a better solution than move -b
for the script from 第 9.5.3 节 “例子” to prevent overwriting of existing files. For instance, test whether or not a file exists. Don't do unnecessary work!
Rewrite the whichdaemon.sh
script from 第 7.2.4 节 “布尔操作”, so that it:
Prints a list of servers to check, such as Apache, the SSH server, the NTP daemon, a name daemon, a power management daemon, and so on.
For each choice the user can make, print some sensible information, like the name of the web server, NTP trace information, and so on.
Optionally, build in a possibility for users to check other servers than the ones listed. For such cases, check that at least the given process is running.
Review the script from 第 9.2.2.4 节 “计算一个平均数”. Note how character input other than q is processed. Rebuild this script so that it prints a message if characters are given as input.