如何在 cd 命令后自动将 pwd 回显到 bash shell?我的老旧 Solaris 系统可以做到这一点,但我找不到如何在 Ubuntu 中做到这一点。实际上我希望它看起来像下面这样,这样我就不必一直输入 pwd!
user@server[USR@SOL] cd
/export/home/user
user@server[USR@SOL] cd ..
/export/home
user@server[USR@SOL] cd ..
/export/
谢谢
答案1
简短的回答:您有一个PS1
描述提示结构的环境变量。包含\w
该变量将导致当前工作目录显示在提示中。
长答案:这通常在 中完成~/.bashrc
。如果在那里省略或删除了它,则可以使用以下代码(取自标准.bashrc
)重新创建标准 Ubuntu 提示符,如下所示:
user@host:pwd$
代码如下:
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
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