Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 7.1 Why Change Your Prompt? Chapter 7
Setting Your Shell Prompt
Next: 7.3 C Shell Prompt Causes Problems in vi, rsh, etc.
 

7.2 Basics of Setting the Prompt

The prompt displayed by your shell is contained in a shell variable (6.8) called prompt in the C shell and PS1 in the Bourne shell. As such, it can be set like any other shell variable. [bash and tcsh have plenty of extra features for those two variables. There are examples in later articles. -JP]

So, for example, if I wanted to change my C shell prompt to include my login name, I might put the following command into my .cshrc file:

set prompt="tim % "

(It's helpful to leave the % at the end so that it remains obvious that this is a C shell. The space after the % makes the command you type stand out from the rest of the prompt.)

Or if I wanted to put in the name of the system I was currently logged in on, I might say:

`...` uname -n 
set prompt="`uname -n` % "

If I wanted to include the history number for each command, (11.1) I'd say:

set prompt="\! % "

Or if I wanted all three things:

set prompt="tim@`uname -n` \!% "

This will give me a prompt like this:

tim@isla 43%

- TOR


Previous: 7.1 Why Change Your Prompt? UNIX Power ToolsNext: 7.3 C Shell Prompt Causes Problems in vi, rsh, etc.
7.1 Why Change Your Prompt? Book Index7.3 C Shell Prompt Causes Problems in vi, rsh, etc.

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System