用户可以定制自己的shell环境 ,方便使用。
1、.bashrc文件
shell在启动前会去执行一些配置文件,.bashrc就是其中一个。这个文件放在~文件夹(即用户的home文件夹)下。可以修改这个.bashrc文件,这样在每次shell启动前就能执行一些命令。通常这些命令都是用来定制环境的,如设置shell变量,alias命令等。设置shell变量的语法为"name=value"或"export name=value",alias命令语法为"alias name=value",非常简单,但特别实用。
2、shell变量PS1和PS2
登陆shell后,每行开始都会显示一串字符串,可能是主机名或当前路径名称等等,一般称其为shell提示符。shell变量PS1就是用来设置shell提示符字符串的,只要修改PS1的指就可以替换shell提示符,如PS1="/w—> "将shell提示符改成当前路径名。其中,/w代表当前路径。下表列出了PS1使用的转义字符(from "Learning the bash shell"):
Command
|
Meaning
|
/a
|
The ASCII bell character (007)
|
/d
|
The date in "Weekday Month Day" format
|
/e
|
The ASCII escape character (033)
|
/H
|
The hostname
|
/h
|
The hostname up to the first "."
|
/n
|
A carriage return and line feed
|
/s
|
The name of the shell
|
/T
|
The current time in 12-hour HH:MM:SS format
|
/t
|
The current time in HH:MM:SS format
|
/@
|
The current time in 12-hour am/pm format
|
/u
|
The username of the current user
|
/v
|
The version of bash (e.g., 2.00)
|
/V
|
The release of bash; the version and patchlevel (e.g., 2.00.0)
|
/w
|
The current working directory
|
/W
|
The basename of the current working directory
|
/#
|
The command number of the current command
|
/!
|
The history number of the current command
|
/$
|
If the effective UID is 0 print a #, otherwise print a $
|
/nnn
|
Character code in octal
|
//
|
Print a backslash
|
/[
|
Begin a sequence of non-printing characters, such as terminal control sequences
|
/]
|
End a sequence of non-printing characters
|
在shell命令行中输入echo "aaa并按下enter时,由于引号没有配对,shell会跳入下一行,提示用户继续输入。此时shell提示符变成"> "了,这就是PS2的值。PS2也是shell变量,可以很容易被修改。例如执行PS2="< ",提示符将换成"> "。
3、其他SHELL变量
另外,经常接触的shell变量还有PATH、HOME和PWD