Changing Your ksh Prompt


Changing Your ksh Prompt

Like bash, ksh has two prompts you can edit:

  • The main prompt that you usually think of as the shell prompt, called PS1.

  • A secondary prompt that you see when the system requires additional information to complete a command. Logically, this prompt is called PS2.

You can change either of these prompts using the following steps (we'll modify PS1 in the example). You start by finding your prompt statement (Code Listing 8.17), then modifying it in your editor.

Code Listing 8.17. List your zsh configuration files and look for a prompt statement.

$ grep PS1 /etc/profile ~/.profile ~/  .kshrc /home/users/e/ejray/.profile:PS1="$ " /home/users/e/ejray/.profile:export PS1 $ 

To change your ksh prompt:

1.

grep PS1 /etc/profile ~/.profile ~/.kshrc

To begin, search through the configuration files located in your home directory and in the /etc directory for your prompt statement. It'll look something like PS1="$ " or PS1='$PWD $', as shown in Code Listing 8.17. Keep in mind that you can edit the files in your home directory only, not those in the /etc directory.

The Setting Your ksh Prompt Promptly sidebar will help translate these symbols.

2.

vi .profile

Use your favorite editor to edit the configuration file with the PS1 setting in it or to add a PS1 setting to a configuration file in your home directory.

3.

PS1="$LOGNAME in $PWD $ "

Change the prompt to display the information you wantin this case, the user name and the current working directory.

Tip

  • Note the trailing space in the prompt code: PS1="$ ". This space keeps your commands from bumping into your prompt.


Setting your ksh Prompt Promptly

You can set your ksh prompt to contain some different kinds of informationbut not as much as with zsh or bash shells. The following list shows you what code to use to add certain kinds of information to your prompt (as well as help you translate the code in your existing prompt):

  • $LOGNAME shows the userid of the current userthat's you.

  • ${PWD##*/} shows the current working directory without the path.

  • $PWD shows the current working directory with the path.

  • $HOST shows the host name of the computer





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net