这是的一部分我的〜/ .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