LiveFire Labs - Online UNIX Training - Company Logo


Online UNIX Training with Hands-on Internet Lab


"Eliminate the expense and inconvenience of classroom training without eliminating the classroom experience."

 


Home
Internet Lab
Console Access
Sample Course

Student Login


LiveFire Labs' UNIX Tip, Trick, or Shell Script of the Week - View


Questions? Call
1.888.843.1637 or send us email

November 3, 2003 - How to Include the Current/Working Directory in your Command Prompt (the PS1 shell variable)

The tip "Changing your Command Prompt (the PS1 shell variable)" showed how to customize the command prompt by redefining the PS1 shell variable.  The example used for this tip demonstrated how you could add your username and the hostname to the prompt.

Another desirable command prompt customization is to display the current directory (also known as the working directory) as part of the prompt.  When the cd command is used to change to another directory, the prompt should automatically be updated to reflect the change.

This functionality can be achieved by defining PS1 as follows:

export PS1=[${LOGNAME}@$(hostname)]'$PWD>'

Similar to the first tip on the PS1 variable, the username and hostname have also been included in this example.

Taking this new definition for a test drive illustrates how it is updated each time the cd command is executed:

$ pwd
/export/home/livefire
$ export PS1=[${LOGNAME}@$(hostname)]'$PWD>'
[livefire@hawk]/export/home/livefire>cd /tmp
[livefire@hawk]/tmp>cd /usr/bin
[livefire@hawk]/usr/bin>cd ..
[livefire@hawk]/usr>cd
[livefire@hawk]/export/home/livefire>

Notice that using cd with no arguments is a quick way to return to your home directory.  Over time you will discover how useful this feature is.


Learn more...
  

If you are new to the UNIX or Linux operating system and would like to learn more, you may want to consider registering for LiveFire Labs' UNIX and Linux Operating System Fundamentals online training course.

If you already have a solid grasp of the fundamentals but would like to learn more about the Korn shell and basic and advanced shell scripting, taking our Korn Shell Scripting course will be beneficial to you.

Our innovative hands-on training model allows you to learn UNIX by completing hands-on exercises on real servers in our Internet Lab.


More Tips...

· 
Popular UNIX Tips from the Past

spacer Box Border
 

Receive the UNIX Tip, Trick, or Shell Script of the Week by Email


First Name:


Email Address:






   1.888.843.1637

Home - Contact us - Company info - Privacy Statement   

 
©2002-2003 LiveFire Labs.  All rights reserved.
Linux® is a registered trademark of Linus Torvalds, author and developer of this public domain operating system.
UNIX® is a registered trademark of The Open Group in the United States and other countries.