PS1参数详解
From:? http://www.safe5.com/patch/xitongloudong/linux/20120305/27116.html
bash Shell Prompt Characters Character
\a The bell character
\d The date in the format ‘‘Day Month Date’’
\e The ASCII escape character
\h The local hostname
\H The fully qualified domain hostname
\j The number of jobs currently managed by the shell
\l The basename of the shell’s terminal device name
\n The ASCII newline character
\r The ASCII carriage return
\s The name of the shell
\t The current time in 24-hour HH:MM:SS format
\T The current time in 12-hour HH:MM:SS format
\@ The current time in 12-hour am/pm format
\u The username of the current user
\v The version of the bash shell
\V The release level of the bash shell
\w The current working directory
\W The basename of the current working directory
\! The bash shell history number of this command
\# The command number of this command
\$ A dollar sign if a normal user, or a pound sign if the root user
\nnn The character corresponding to the octal value nnn
\\ A backslash
\[ Begins a control code sequence
\] Ends a control code sequence
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PS1使用詳解
使用方法:
# PS1='自定義內(nèi)容'
注意兩邊的單引號(hào)
示例: PS1='(\u@\H \d \t)\$'
-------------------------------------------------------------------------------
PS1:就是用戶平時(shí)的提示符。
PS2:第一行沒輸完,等待第二行輸入的提示符。
Linux系統(tǒng)提示符是用系統(tǒng)變量PS1來定義的。
一般系統(tǒng)默認(rèn)的形式是:[username@host 工作目錄]$.
用echo $PS1可以得到PS1的值,即PS1="[\u@\h\w]"\$
登錄后可以更改PS1的顯示樣式,但是當(dāng)退出重啟登錄進(jìn)入系統(tǒng)后,樣式又變成系統(tǒng)默認(rèn)的樣式了,如果要徹底改變它的樣式,只能從配置文件中改。
PS是在用戶根目錄下的.bash_profile中定義的。
如
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
#以下是設(shè)定的PS1的值
PS1="[\u@\h \w]\$"
PATH=$PATH:$HOME/bin
#使用export把PS1輸出,以使它可以在子shell中生效,這會(huì)造成ROOT用戶的也采用此樣式
#export PS1 要慎用
export PATH
unset USERNAME
下面簡(jiǎn)單說說環(huán)境下默認(rèn)的特殊符號(hào)所代表的意義:
\d :代表日期,格式為weekday month date,例如:"Mon Aug 1"
\H :完整的主機(jī)名稱。例如:我的機(jī)器名稱為:fc4.linux,則這個(gè)名稱就是fc4.linux
\h :僅取主機(jī)的第一個(gè)名字,如上例,則為fc4,.linux則被省略
\t :顯示時(shí)間為24小時(shí)格式,如:HH:MM:SS
\T :顯示時(shí)間為12小時(shí)格式
\A :顯示時(shí)間為24小時(shí)格式:HH:MM
\u :當(dāng)前用戶的賬號(hào)名稱
\v :BASH的版本信息
\w :完整的工作目錄名稱。家目錄會(huì)以 ~代替
\W :利用basename取得工作目錄名稱,所以只會(huì)列出最后一個(gè)目錄
\# :下達(dá)的第幾個(gè)命令
\$ :提示字符,如果是root時(shí),提示符為:# ,普通用戶則為:$
我們可以通過設(shè)置PS1變量使提示符成為彩色。在PS1中設(shè)置字符序列顏色的格式為:
\[\e[F;Bm\]
其中``F''為字體顏色,編號(hào)30~37;``B''為背景色,編號(hào)40~47。
可通過``\e[0m''關(guān)閉顏色輸出;特別的,當(dāng)B為1時(shí),將顯示加亮加粗的文字,詳細(xì)請(qǐng)看下面的顏色表與代碼表。
顏色表
前景 背景 顏色
---------------------------------------
30 40 黑色
31 41 紅色
32 42 綠色
33 43 黃色
34 44 藍(lán)色
35 45 紫紅色
36 46 青藍(lán)色
37 47 白色
代碼 意義
-------------------------
0 OFF
1 高亮顯示
4 underline
5 閃爍
7 反白顯示
8 不可見
如果想要設(shè)置終端提示符的樣式只要把$PS1在~/.bahrc指定即可比,比如我的設(shè)置如下:
設(shè)置一:
PS1="\[\e[32m\][\u@\h \w]$\[\e[m\]"
export PS1
效果:
[LinuxSong@test ~]$
設(shè)置二:
if [ $TERM = 'linux' ]; then
export PS1="[\[\e[36;1m\]\u@\h\[\e[31;1m\]\w\[\e[32;1m\]]> "
zhcon --utf8
clear
elif [ $TERM = "xterm" ]; then
export PS1="[\[\e[31;1m\]\w\e[0m]> "
fi
總結(jié)
- 上一篇: 一个托盘程序演示 -闹钟 Alert
- 下一篇: gulp版本号管理插件注意事项