Bash Prompt HOWTO:
Prev | Chapter 4. External Commands | Next

# 4.3. What to Put in Your Prompt

You'll find I put username, machine name, time, and current directory name in most of my prompts. With the exception of the time, these are very standard items to find in a prompt, and time is probably the next most common addition. But what you include is entirely a matter of personal taste. Here is an interesting example to help give you ideas.

Dan's prompt is minimal but very effective, particularly for the way he works.

    [giles@nikola:~]$ PS1="\!,\l,\$?\$ "
    1095,4,0$ non-command
    bash: non-command: command not found
    1096,4,127$

Dan doesn't like that having the current working directory can resize the prompt drastically as you move through the directory tree, so he keeps track of that in his head (or types "pwd"). He learned Unix with csh and tcsh, so he uses his command history extensively (something many of us weaned on Bash do not do), so the first item in the prompt is the history number. The second item is the tty number, an item that can be useful to "screen" users. The third item is the exit value of the last command/pipeline (note that this is rendered useless by any command executed within the prompt - you can work around that by capturing it to a variable and playing it back, though). Finally, the "\$" is a dollar sign for a regular user, and switches to a hash mark ("#") if the user is root.

Prev | Home | Next
External Commands in the Prompt | Up | Saving Complex Prompts