DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Customizing your environment

Changing your prompt

A prompt will appear after you have logged into your system. The UNIX system stores this prompt in a variable.

To change your prompt, you reset the value of the prompt variable.

In the Bourne and Korn shells, the prompt variable is called PS1 (prompt string 1). In the C shell, the prompt variable is called prompt.

All three shells have a secondary prompt as well as the main prompt. This secondary prompt is shown when you type a command that makes the shell expect further input.

For example, in the Bourne shell, the secondary prompt is ``>'' by default:

   $ for i in *.tut
   >
Here, you are saying to the shell ``for every file (i represents every file) ending in .tut ...'' The shell gives you a secondary prompt because it needs more information to complete your command.

In the Bourne and Korn shells, the secondary prompt is stored in the variable PS2 (prompt string 2), which you can reset. You cannot reset the secondary prompt in the C shell. To reset PS2 in sh or ksh, follow the instructions below, substituting PS2 for PS1.

To reset your prompt in the Bourne or Korn shells, type PS1=value where value is the value you want to assign to the prompt variable.

For example, to set your prompt to say ``Yo'', you would add the following line to your .profile or .kshrc:

   PS1=Yo
C-shell users would add the following line to their .login:
   set prompt=Yo

Q: When I change my prompt, I lose the space between my prompt and where the command line starts. How do I get this back?

A: To keep the space between the prompt and the command line, you need to put a space after your new prompt. To get the shell to notice the space, you need to enclose the whole prompt string in double quotes.

In ksh or sh, add the following line to your .profile:

PS1="Hello friend "
In csh, add the following line to your .login:
set prompt="Hello friend "

Q: How do I get my prompt to show the current directory, like on DOS?

A: In sh, add the following line to your .profile:

nd()	{ cd $* ; PS1="`pwd` "; }
Now, use the command nd, which you just created, to change to a new directory and display the directory as the prompt.

In ksh, add the following line to your .kshrc:

PS1='$PWD '
In csh, add the following lines to your .cshrc: (You do not need to add the lines that start with #. These are comments.)
# make a command doprompt that sets the prompt to the working directory
alias doprompt 'set prompt="`pwd` "'
# set the prompt the first time around
doprompt
# alias the cd command to change directories and reset the prompt
alias cd 'chdir !* || doprompt'

Next topic: Setting your path
Previous topic: Your environment

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003