Bash

如何讓我的 PS1 bash 會話始終顯示整個密碼?

  • February 2, 2018

相關.bashrc部分:

if [ "$color_prompt" = yes ]; then
   if [[ ${EUID} == 0 ]] ; then
       PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
   else
       PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '
   fi
else
   PS1='${debian_chroot:+($debian_chroot)}\u@\h \w \$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
   PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h \w\a\]$PS1"
   ;;
*)
   ;;
esac

問題是,我如何使它不縮短pwd主目錄中的 if ,從而pwd在 PS1 中始終顯示整體。

通過替換\w\WPS1with中解決$PWD

if [ "$color_prompt" = yes ]; then
   if [[ ${EUID} == 0 ]] ; then
       PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\h\[\033[01;34m\] $PWD \$\[\033[00m\] '
   else
       PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]$PWD \$\[\033[00m\] '
   fi
else
   PS1='${debian_chroot:+($debian_chroot)}\u@\h $PWD \$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
   PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h \$PWD\a\]$PS1"
   ;;
*)
   ;;
esac

引用自:https://unix.stackexchange.com/questions/421362