预计阅读本页时间:-
Examples
The bash archive also includes an examples directory. This directory contains some subdirectories for scripts, functions, and examples of startup files.
The startup files in the startup-files directory provide many examples of what you can put in your own startup files. In particular, bash_aliases gives many useful aliases. Bear in mind that if you copy these files wholesale, you'll have to edit them for your system because many of the paths will be different. Refer to Chapter 3 for further information on changing these files to suit your needs.
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
The functions directory contains about 50 files with function definitions that you might find useful. Among them are:
basename
The basename utility, missing from some systems
dirfuncs
Directory manipulation facilities
dirname
The dirname utility, missing from some systems
whatis
An implementation of the Tenth Edition Bourne shell whatis builtin
whence
An almost exact clone of the Korn shell whence builtin
Especially helpful, if you come from a Korn shell background, is kshenv. This contains function definitions for some common Korn facilities such as whence, print, and the two-parameter cd builtins.
The scripts directory contains over 20 examples of bash scripts. The two largest scripts are examples of the complex things you can do with shell scripts. The first is a (rather amusing) adventure game interpreter and the second is a C shell interpreter. The other scripts include examples of precedence rules, a scrolling text display, a "spinning wheel" progress display, and how to prompt the user for a particular type of answer.
Not only are the script and function examples useful for including in your environment, they also provide many alternative examples that you can learn from when reading this book. We encourage you to experiment with them.
[2] This configuration information pertains to bash version 3.0 and later. The configuration and installation for earlier versions is fairly easy, although it differs in certain details. For further information, refer to the INSTALL instructions that came with your version of bash.