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?
You can change the BASH prompt temporarily by using the export command. This command changes the prompt until the user logs out. You can reset the prompt by logging out, then logging back in.
PS1 is one of the few variables used by the shell to generate the prompt. As explained in the bash manual, PS1 represents the primary prompt string (hence the “PS”) - which is what you see most of the time before typing a new command in your terminal.
By default, bash shows just your current directory, not the entire path. To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd.
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 \$'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With