3.5 Setting the Command Prompt

   

The PS1 variable controls the appearance of the user command prompt. A user can modify the command prompt by setting a desired value of PS1 . If you want to change your command prompt from a simple $ sign to " My Computer => ", you can use the following command.

 $  PS1="My Computer =>"  My Computer => 

As you notice, the command prompt changes as soon as you change the value of PS1 . Just to remind you, you also have to export the PS1 variable to make this change visible in the sub- shells .

Adding Useful Information to the Prompt

You can play some tricks with the command prompt to display useful information. For example, it is very handy if the prompt displays the current directory, as it can be hard to remember which directory you are in. We can make a slight change to PS1 to display the current directory path .

 $  PS1="My Computer $PWD =>"  My Computer /home/boota => 

As you can see, the prompt changes and the current directory is there. Now, whenever you use the cd command to change the current directory, the PWD environment variable changes, and your prompt also changes to show the new current directory. Similarly, it is possible to have your login name and the computer name in the command prompt along with the current directory, as shown in this example.

 $  PS1= "`whoami` on `uname -n` $PWD =>"  boota on myhp /home/boota => 

Note

This is very useful if you work in a network environment and often log into different machines with different names . It is the command prompt that tells you which machine you are on, which login name you are using, and what the current directory is. Does this seem interesting to you? You can also try to change your prompt to include the date and time, blinking characters , and so on, depending on the type of terminal you are using.



   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

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