Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

PS1 Command Prompts Tips

Expert Oracle Database Tips by Donald BurlesonMarch 22, 2015

Variables and Commands in Prompts

Customizing the Prompt

The command promptyou get when you connect to a command line session is highly customizable.  I have used a simplified prompt of just a dollar sign ($) in the examples in this book, but the default prompt in Linux includes the user name, host name and the current directory.

[jemmons@oelinux-test1 u01]$

The prompt is set by defining the PS1 shell variable.  If you want the prompt to just contain text, simply define it just like any other variable.

$ PS1=:
 

:PS1=': '
: PS1='Enter a command: '

Enter a command: PS1=$
 
$PS1='$ '
$
 

Changes to the PS1 variable are seen immediately in the current session.  In the example above, first set the prompt to a colon (:).  It is seen on the next line that with just the colon, your prompt is not separated from your command.  To make the prompt more obviously separate from the command,  set PS1 to a colon with a space after it.  To set a variable to a value with a space in it, enclose the value between single or double quotes.  The space makes it a bit more clear where the prompt ends and the command begins.

Next, change the prompt back to the familiar dollar sign but now notice that the default prompt is not just a dollar sign, but rather, a dollar sign followed by a space, so set PS1 to reflect that. When you get to a prompt you are happy with, put the definition of it in your .bash_profile file with other alias definitions.  Now every time you log in, your prompt will automatically be set and ready to go.

Special Prompt Characters

Bash allows several special characters to be used in a user's prompt which will then be expanded when the prompt is printed.  These characters can be used in combination with text in the prompt, but always begin with a backslash (\).  Here are a few of the more useful special characters:

Special Character Description
\d The date spelled out in the form of 'Weekday Month Date'??
\@ The current time in 12 hour format with AM/PM
\u The username of the current user
\h The hostname of the system you are on
\w The current working directory

Table 8.1:   Sample of Special Prompt Characters

Here are a few examples of how these special characters can be used in a prompt.  Note that the prompt following the change represents the results of that change.

$ PS1='\d \@ $ '
 
Thu Oct 12 04:34 PM $ PS1='\u@\h$ '
oracle@ oelinux-test1$ PS1='\w $ '
 
~ $ cd /usr/local
 
/usr/local $ 
 
The change directory (cd) command in this example is used to demonstrate that the \w character is showing the user's present working directory.  Commands and shell variables can also be used in command prompts.

Variables and Commands in Prompts

Almost anything can be put in your prompt with shell variables and commands.  Oracle administrators often want their current ORACLE_SIDlisted in their command prompt.  This is easily accomplished:

$ PS1='$ORACLE_SID $ '
 
oss $

Be sure to use single quotes when enclosing variables and commands within the prompt.  If double quotes are used, any variables or commands are interpreted and substituted when the prompt is set but are not updated if the value changes during the session.  By using single quotes, the variables and commands are substituted when the prompt is displayed. If, for instance, the ORACLE_SID variable is changed to connect to a different database, the new value for ORACLE_SID is reflected in the prompt.

To use commands in the prompt, they must be enclosed between two grave symbols (`), more commonly called backquote or backtick in UNIX circles.  Here is an example:

$ PS1='`uptime | cut -f 3-5 -d ","`$ '
 
   load average: 0.03, 0.04, 0.01$
 
Here the PS1 prompt is set to show the current load average of the system by using the uptime and cut commands.  Everything within the back quotes is evaluated and the result substituted in the prompt.  Then $ is added to make it clear where the prompt ends.

I suggest keeping your prompt simple.  Remember, whatever you put in there will be executed over and over while you are on the system.  Most of the time, I find username and hostname and perhaps ORACLE_SID to be sufficient.

$ PS1='\u@\h $ORACLE_SID $ '
 

oracle@ oelinux-test1 oss $
 
A secondary prompt is used when entering commands on multiple lines.  This PS2 promptis seen when a backslash (\) is entered to continue a command on the next line.  The default is usually good for this since you do not see it much, but if you wish to change it, set the PS2 environmental variable in the same way you would set PS1.

Prompts PS3 and PS4 can also be set but these are rarely seen.  PS3 is used only in very specific shell syntax and PS4 is used when using a special trace option within the shell.

Conclusion

A handful of meaningful customizations can make the Linux environment easier to use and more flexible.  Changes to the login shell, variables and binary search path may sometimes be necessary when setting up new software.

It is important to remember that many of these customizations change the way the shell works and can affect how software runs.  Changes to the PATH variable in particular can have unexpected consequences.

The next chapter will examine the use of the at and cron utilities when scheduling tasks.

 

 

 
 
 
Get the Complete Details on
Linux System Management for Oracle DBAs  


The landmark book "Linux for the Oracle DBA: The Definitive Reference" provides comprehensive yet specific knowledge on administering Oracle on Linux.   A must-have reference for every DBA running or planning to run Oracle on a Linux platform.

Buy it for 30% off directly from the publisher.
 


 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster