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

April 21, 2003 (Tip) - Changing your Command Prompt (the PS1 shell variable)

The UNIX shell displays a command prompt when the system is ready to accept commands on the command line.  The default command prompt is a single character (typically $ or #).

Changing or customizing the command prompt makes your life easier when jumping from system to system, or when logging in as multiple users on a single system (e.g. your personal/non-privileged account and root).  To customize your prompt you will need to modify the PS1 shell variable.

PS1 stands for "prompt string 1" and defines the primary prompt string.  If you wanted your command prompt to contain the current username and hostname separated by the "@" character and enclosed in brackets (e.g. [root@hawk] #), PS1 would need to be re-defined with the following command(s):


export PS1="[${LOGNAME}@$(hostname)] # "

or

PS1="[${LOGNAME}@$(hostname)] # "
export PS1

The shell variable LOGNAME contains the username you logged in with, and $(hostname) will execute the hostname command which will print the name of the current host system.  Exporting PS1 makes it available to any subshells you create during the login session.

Since PS1 in this example was re-defined on the command line, it will be lost as soon as you log out.  To retain this definition across login sessions you will need to add the previous command(s) to your shell initialization file (.profile if the Korn shell is your default shell).

NOTE: The commands in this tip were tested with the Korn shell only.


Learn more...  

If you are new to the UNIX or Linux operating system and would like to learn more about shells, shell commands, and shell variables, 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.