============================= Setting the BASH shell prompt ============================= -Ian! D. Allen - idallen@idallen.ca - www.idallen.com If you have several Unix machines in your lives and you use remote login, you may be uncertain about which machine is receiving your keystrokes. For Bourne-style shells (including BASH) you can change the shell prompt string to anything you like by changing the contents of environment variable PS1, e.g.: $ PS1='Yes Master? ' Yes Master? date Fri Jan 19 10:36:30 EST 2007 Yes Master? The BASH shell uses special escape sequences in the prompt string to mean things such as your userid ("\u"), your host name ("\h"), and the last part of the pathname that is your current working directory ("\W"). (See the BASH man page for lots of other goodies.) In the following sequence of commands issued on machine "foobar", you can see the original PS1 contents and the new contents and how each affects the prompt being displayed (note the use of single quotes): bash-2.04$ hostname foobar bash-2.04$ bash-2.04$ echo "$PS1" \s-\v\$ bash-2.04$ PS1='[\u@\h \W]\$ ' [idallen@foobar idallen]$ cd /tmp [idallen@foobar tmp]$ As with the value of any shell variable, this change to PS1 vanishes when this shell exits. To make a variable change permanent across logout/login, you must add the line that sets PS1 to one of your login script files (e.g. to the file .bash_profile in your home directory) and also export the PS1 variable to allow other child shells to inherit it: In file .bash_profile in your home directory add these lines: PS1='[\u@\h \W]\$ ' export PS1 The above lines will be executed every time you log in, and the PS1 variable will be exported to all subshells of the login shell. You can also set the prompt in the $HOME/.bashrc file, which will affect every BASH shell you run, not just shells that are children of your login shell. The Linux file /etc/profile often contains script that sets your prompt for you. Look at it for ideas.