Depending on your Unix system, by default you might see as your prompt just a dollar sign ($), or perhaps a dollar sign and date, or other information as outlined in the Setting Your bash Prompt Promptly sidebar. You can set your prompt to include information that’s handy for you.
[ejr@hobbes ejr]$ grep PS1 ~/.bash* → ~/.bashrc /etc/bashrc /home/ejr/.bashrc:PS1="u d $ " /etc/bashrc:PS1="[u@h W]$ " [ejr@hobbes ejr]$ |
You actually have multiple prompts in bash:
The main prompt that you usually think of as the shell prompt. This prompt is called PS1.
A secondary prompt that you see when the system requires additional information to complete a command. Logically, this prompt is called PS2.
You can change either of these prompts using the following steps. You start by finding your prompt statement (Code Listing 8.13), then modifying it in your editor (Figure 8.4).
1. | grep PS1 ~/.bash* "~/.bashrc → /etc/bashrc To begin, search through the configuration files located in your home directory and in the /etc directory to find your prompt statement. It’ll look something like PS1=”$ “ or PS1=”[u@h W]$ “, as shown in Code Listing 8.13. The Setting Your bash Prompt Promptly sidebar will help translate these symbols. |
2. | |
3. | PS1="u d $ " For example, we often set our prompt to include the userid (because we have enough different accounts on different systems that we need a reminder) and the date (because we’re scattered). We’re adding this at the end of the file so it will take precedence over the PS1 setting in the /etc/bashrc file that is referenced from the ~/.bashrc file (Figure 8.4). |
4. | Save the file and exit from the editor. |
5. | su - ejr Log in again with your changed prompt to try it out. |
✓ Tips
Note the trailing space in the prompt code: PS1=”u d $ “. This space can help make it easier to use the prompt because it keeps your commands from bumping into your prompt.
Consider changing your PS1 environment variable at the shell prompt, as discussed in Chapter 3, before you make changes in your configuration files. This way, you can try out a modified shell prompt before you change it in your configuration files.
Setting Your bash Prompt PromptlyYou can set your prompt to contain all sorts of information. The following list shows you what code to use to add certain kinds of information to your prompt (as well as help you translate the code in your existing prompt):
|