By default, the C shell uses the percent sign (%) as a prompt. You can change the default by redefining the C shell’s
prompt variable , using this general form:
% set prompt=value
As another example, if I wanted to change my prompt to include my user ID, I would enter the following:
% set prompt="danielg %"
danielg %
The prompts you have seen up until now have included only literal characters.
Prompts also can include shell features such as variables and the history number, the command number tracked by the history feature.
When the history feature is turned on, each command is assigned a consecutive number so you can refer to previous commands. Numbering
your commands in order makes it easier to track them. For example:
1 % cd
2 % cp old new
3 % rm new
4 %
To include the history number, use the characters \! in the prompt definition. Here is a sample command and the result:
% set prompt="\! %"
15 %
This example assumes that the set command was the 14
th command of my session. The next command will be number 15,
and the prompt will add on to this number as new commands are entered. The ! character produces the command number, but the ! must
have a backslash (\) before it. Without the \, the prompt definition is permanently set to the history number of this particular
set prompt command and will not increase.
If you display your current directory in your prompt, you can avoid entering the pwd command all the time. One way to avoid
updating the prompt every time you change directories isto create an alias to the cd command:
In aliases, \!* stands for all arguments of the current command, which is cd in this case. The \!* causes
the alias to work whether you use the plain cd command (without an argument) or whether you use the cd directory
form. The whole alias definition is enclosed in single quotes (') so that it is interpreted as one argument.
In plain English, the entire alias definition reads as follows: “Run the cd command along with its arguments. Then set
the prompt to the name of the directory you just went to.”
In the next lesson, storing your custom settings will be discussed.