Bash家族 & C-Shell家族常见的提示结束符:
所有的shell都包含有两部分: 字符+一个空格(空格属于提示的一部分)
"SHELL" "PROMPT-CHARACTER"
Bash $
Korn Shell $
C-Shell %
Tcsh % or >
Super-user #
如何修改登录提示符?
所有的 B-SHELL 都将 提示值 存储在 $PS1
的环境变量里。
所有的 C-SHELL 都将 提示值 存储在 prompt
的shell变量中。
一般使用三种手段:
1.Insert the value of a variable into the prompt.
2.Use an escape character to make use of a variety of special codes.
3.Insert the results of a command into the prompt. (This is called command substitution.)
下面仔细介绍(重点关注B-SHELL):
1.直接插入值或变量实现。
export PS1="${LOGNAME}$ "
# **注意下面的区别:每次显示提示符,都会引用到PS1变量。
export PS1="${USER}$ "
export PS1='${USER}$ ' --这个才会实时改变!
export PS1="${PWD}$ "
export PS1='${PWD}$ ' --这个才会实时改变!
export PS1='${RANDOM}$ '
2.使用转义符的特殊码。
# 只有bash , tcsh 才允许使用特殊码。
# 每个特数码都包含一个转义字符和一个字符!
export PS1='\u \d \@$ '
root 五 9月 16 01:25 下午$
3.使用命令转换。
通过将一条命令 封装在`` 中,使得可以将其嵌入另一条命令中!
name="today is `date`"
echo $name
today is 2016年 09月 16日 星期五 13:40:37 CST
export PS1="`basename ${SHELL}`$ "
–备注:
1.经常用于提示的环境变量。
2.经常使用的提示特殊码。