dook dook - 21 days ago 6
Linux Question

Bash PS1 shows $ instead of # for root

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 \$"
.

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?

Answer
export PS1="\w \$"

This doesn't set $PS1 to \w \$, it sets it to \w $, as you can see if you type:

echo "$PS1"

Use single quotes:

export PS1='\w \$'
Comments