shell 提示符
rivsidn@rivsidn:~$ echo ${PS1} \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
The default $PS1 in Ubuntu consists of three parts:
-
\[\e]0;\u@\h: \w\a\]This is an escape sequence which will set the terminal title text to
$USER@$HOST: $PWD.\[and\]indicate the beginning and end of a sequence of non-printing characters.\eis an ASCII escape character.]0;is the specific escape sequence to set the terminal icon and title inxtermcompatible terminals\uexpands to the username of the current user.@is a literal @.\hexpands to the hostname.:is a literal colon character.\wexpands to the current working directory.\ais an ASCII bell character. -
${debian_chroot:+($debian_chroot)}If you're in a chroot environment, this will expand to the name of the chroot in parentheses.
${var:+OTHER}evaluates to$OTHERifvaris set, otherwise as null string.$debian_chrootis a variable initalized in/etc/bash.bashrcto the contents of the file/etc/debian_chroot. Thus if your chroot environment includes this file, the prompt will include the contents of that file as an indication for which chroot the shell currently operates in. -
\u@\h:\w\$This is the actual prompt you typically see.
\u,@,\h,:,\ware as above.\$expands to a number sign # if the effective uid is zero (i.e. user is root), otherwise it expands to a dollar sign $.
Resources
参考资料:
浙公网安备 33010602011771号