這是的一部分我的〜/ .bashrc:bash提示符殼
prompt(){
local EXIT="$?" # return code
PS1=""
local red="\[\033[0;31m\]" # text colour
local purple="\[\033[0;35m\]" # text colour
local normal="\[\033[0m\]" # text colour
if [ $EXIT == 0 ]; then # $EXIT colour based upon its value
local return="${normal}${?}"
else
local return="${red}${?}${normal}"
fi
PS1+="${normal}[${purple}\\D{%-l:%M%P}${normal}]${return} \\[\\e]0; \
\\[email protected]\\h: \\w\\a\\]${debian_chroot:+($debian_chroot)}\\[email protected]\\h:\\w\\$ "
}
export PROMPT_COMMAND=prompt
這是我在提示殼侏儒末端(正確顯示):
[5:01pm]0 [email protected]:~$
但是當我切換到TTY控制檯,我登錄後,該顯示:
[5:05pm]0 ;[email protected]: [email protected]:~$
這種情況與定期用戶,還可以在同一個操作系統上的同一個筆記本上使用root。 顏色始終正確顯示,唯一的問題是顯示提示的方式。
Sofware版本:
- GNU的bash,版本4.3.11(1)-release(i686的-PC-Linux的GNU),
- Ubuntu的Gnome的14.04。
的PS1值的一些解釋:
[5:01pm] # current time
0 # return/exit code of the last command (0 can be any number;
# if return code has a non-zero value, it turns red)
PS - 目前在TTY控制檯,我需要source ~/.bashrc
能夠運用自己所有的設置。 (1)tty控制檯自己的.bashrc在哪裏? (2)或者如何設置它以使用~/.bashrc
?迅速
作爲公認的答案表明,在PS1變量,有哪些應該被忽略的一部分,不同的行爲
解決方案因此,我只是改變了函數的最後一行
PS1+="${normal}[${purple}\\D{%-l:%M%P}${normal}]${return} \
${debian_chroot:+($debian_chroot)}\\[email protected]\\h:\\w\\$ "
的郵政Scriptum的溶液(PS)
tty控制檯使用~/.bashrc_profile
而不是~/.bashrc
,因爲(如下面評論中的@chepner所述)後者來源於GUI終端仿真器(因爲它通常啓動非登錄交互式shell)。 tty console是一個交互式shell。
我的解決辦法是添加以下~/.bash_profile
:
. ~/.bashrc
'.bashrc'特定於登錄用戶,而不是終端類型。 – chepner
所以我也想到了,但即使我使用相同的信任方式登錄到GUI mod(並因此到gnome終端)和tty控制檯,仍然在tty控制檯中,如果我想使用'〜/ .bashrc '設置,首先我需要輸入'source〜/ .bashrc'命令。 – tukusejssirs
當您登錄到控制檯時,登錄程序正在啓動一個登錄shell,該登錄shell源自'.bash_profile',而不是'.bashrc'。一個GUI終端仿真器通常會啓動一個非登錄交互式shell,其源自'.bashrc',而不是'.bash_profile',因爲您的GUI大概是從登錄shell開始的。在'.bash_profile'中加入'source〜/ .bashrc'是一種非常普遍的做法,這樣'.bashrc'就可以用於所有交互式shell,無論它們是否是登錄shell。 – chepner