Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash PS1 shows $ instead of # for root

Tags:

linux

bash

root

ps1

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?

like image 630
dook Avatar asked May 01 '14 18:05

dook


People also ask

How do I change the shell prompt in bash?

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.

What is bash PS1?

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.

How do I show my working directory in bash?

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.


1 Answers

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 \$'
like image 93
Keith Thompson Avatar answered Oct 02 '22 19:10

Keith Thompson