简体   繁体   English

如何在 bash 提示中显示/隐藏当前工作目录?

[英]How to show/hide current working directory in bash prompt?

When I use Linux console it shows way to current directory "admin@servername:/home$" or not - just "$".当我使用 Linux 控制台时,它显示当前目录“admin@servername:/home$”或不显示的方式 - 只是“$”。 How to turn on/ off this hint (way to directory)?如何打开/关闭此提示(目录方式)? Probably it should be changes in file.bashrc in PS1 = '\u@\h:\w$', but this value in PS1 allready.可能应该是 PS1 中的 file.bashrc 中的更改 = '\u@\h:\w$',但是这个值在 PS1 中已经准备好了。 Here is code sample from.bashrc:这是来自 .bashrc 的代码示例:

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

What exactly should be done to show/ hide way to current directory?究竟应该做什么来显示/隐藏当前目录的方式? Thankyou in advance.先感谢您。

You should look up Bash prompt special characters .你应该查一下Bash提示特殊字符

As you can see in the list, the current working directory is \w , and \a is the bell character, so just remove those.正如您在列表中看到的,当前工作目录是\w ,而\a是响铃字符,所以只需删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM