I have been wondering how to customize the prompt in bash for some time now. However, I never had enough time and energy to look into that. Until now! So, let's do it!
It's actually one of the simpler things. The prompt string is saved in an
$PS1 (prompt string). In order to change it you simply change
the variable's value and it's done. So, let's see...
First we want to know the actual value of the variable. We'll print it out:
\u- user name
\h- host name
\w- full path to current working directory
There are a lot more sequences, you can use. You can even color your prompt! For more information on this topic check out the links at the end of this post.
In order to change the prompt execute the following command:
export PS1="[his dudeness \[email protected]\h:\w]\$ "
This will change your prompt string to something like
[his dudeness [email protected]:~]$
Now, we know how to customize the prompt string, but when you close the shell,
it resets back to default. How to make the changes permanent? All you need to
do is put the command into the
.bashrc file in your home directory.
Actually, here are multiple prompt strings.
$PS1 is the primary one. There
is also a secondary prompt string that is used to indicate continuation of
a multi-line command. For example:
[email protected]:~$ echo "abc\
In this case, the
$PS2 is set to