Bash PS1 为 root 显示 $ 而不是 #
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23414407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash PS1 shows $ instead of # for root
提问by dook
When logging into root, the default prompt when echoed is \s-\v\$
, which shows as bash-4.2#
. I am trying to play around with the bash prompt so it displays the working directory.
export PS1="\w \$"
.
登录 root 时,回显时的默认提示是\s-\v\$
,显示为bash-4.2#
。我正在尝试使用 bash 提示符,以便它显示工作目录。
export PS1="\w \$"
.
The prompt displays correctly, however, the symbol \$
does not transform into a #
, even though my $UID
is 0, which kind of defeats the purpose of omitting the user symbol \u
. Is there something extra I have to add, or does that symbol not work if I export it?
提示显示正确,但是符号\$
并没有转换为 a #
,即使 my$UID
是 0,这违背了省略用户符号的目的\u
。我是否需要添加一些额外的东西,或者如果我导出它,该符号是否不起作用?
回答by Keith Thompson
export PS1="\w $"
This doesn't set $PS1
to \w \$
, it sets it to \w $
, as you can see if you type:
这不会设置$PS1
为\w \$
,而是将其设置为\w $
,正如您在键入以下内容时所看到的:
echo "$PS1"
Use single quotes:
使用单引号:
export PS1='\w $'
回答by wuxb
the slash will be gone in the "". Just need to add one more to keep it. Either
斜线将在“”中消失。只需要再添加一个来保留它。任何一个
export PS1='\w $'
or
或者
export PS1="\w \$"
works for you.
为你工作。
You can combine '' and "". For example:
您可以组合 '' 和 ""。例如:
export PS1="\w blabla"'$'