我想在登录时更改我的 bash 提示符。但即使我更改了 .bashrc 并重新登录后,它仍然提示旧的提示符。请问出了什么问题?
我想获取[\u@\h \W]\$
但是由于某些原因获取不到\s-\v\$
,而且不知道在哪里配置。
此帐户不是 root,但如果需要,我有 root 权限
这是我得到的:
-bash-3.2$ cat .bashrc
PS1='[\u@\h \W]\$'
-bash-3.2$ echo $PS1
\s-\v\$
-bash-3.2$
答案1
您的 shell 很可能是一个交互式登录 shell,因此它不会读取~/.bashrc
而是~/.bash_profile
:
When bash is invoked as an interactive login shell, or as a non-inter‐
active shell with the --login option, it first reads and executes com‐
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
快速而粗略的修复方法可能只是符号链接~/.bashrc
到~/.bash_profile
或反之亦然。这可能会破坏非交互式 shell 的某些功能,例如通过 SSH 远程运行的命令,因此请三思。
请参阅“INVOCATION”部分man bash
以了解更多详细信息。