How to set PS1 to see the ORACLE_SID/TWO_TASK settings (Unix)
February 7th, 2006 By Karl Reitschuster
On Unix the ORACLE_SID is set to connect to the local database. If you have more then one database installed it’s important to know what actual ORACLE_SID or even TWO_TASK (Remote DB) is.
With following PS1 settings done in the .profile the user always sees the ORACLE_SID/TWO_TASK currently set. If TWO_TASK is set then the value of TWO_TASK is prefered.
export NODE=$(uname -n)
export TREV=$(tput rev)
export TRMSO=$(tput rmso)
if [[ ${LOGNAME} = root ]]; then
export PS1='
[ $NODE $TREV$PWD$TRMSO ]
${TWO_TASK:-$ORACLE_SID} #> '
else
export PS1='
[ $NODE $TREV$PWD$TRMSO ]
${TWO_TASK:-$ORACLE_SID} ${LOGNAME}> '
fi
Works with kornshell/bash - output :
[ ZX81 /usr/bin ] isux> [ ZX81 /usr/bin ] isux> export ORACLE_SID=OASIS [ ZX81 /usr/bin ] OASIS isux>
HTH Karl

February 9th, 2006 at 5:55 am
For years, I’m using following PS1 prompt on my Solaris boxes:
$ cat .bashrc PS1='[\u@\h][${ORACLE_SID}:${ORACLE_HOME##*/}][\w]\n[\t]\$ ' $ $ exec bash [oracle@brewers][o10g2:10.2.0][~] [08:54:24]$February 9th, 2006 at 6:55 am
Hi Slava,
your PS1 is very cool too;
I like the extraction of ORACLE_HOME and the shortcut of the current path with ‘~’; But so far only bash compatible;
Greetings
Karl
February 22nd, 2006 at 4:08 am
to get ~ in ksh you can do …
$ X[11]=”";X[1]=’~';PS1=’[${X[1${PWD%%!(${HOME}*)}1]}${PWD#${HOME}}] ‘
[/tmp]
[/tmp]
[/tmp] cd
[~] cd .ssh
[~/.ssh]
February 22nd, 2006 at 10:33 pm
Thanks Laurent for this workaround!
Now my favourite UX prompt is this (added Slavas and your ideas)
export NODE=$(uname -n) export TREV=$(tput rev) export TRMSO=$(tput rmso) export PWDX[11]="";PWDX[1]='~' if [[ ${LOGNAME} = root ]]; then export PS1=' [ $NODE $TREV${PWDX[1${PWD%%!(${HOME}*)}1]}${PWD#${HOME}}$TRMSO ] ${TWO_TASK:-$ORACLE_SID} [${ORACLE_HOME##*/}] # > ' else export PS1=' [ $NODE $TREV${PWDX[1${PWD%%!(${HOME}*)}1]}${PWD#${HOME}}$TRMSO ] ${TWO_TASK:-$ORACLE_SID} [${ORACLE_HOME##*/}] ${LOGNAME} > ' fiGreetings
Karl
PS.: i needed 5 Minutes to understand the Shell logic - i think i got it:-)
February 23rd, 2006 at 2:25 am
Laurent - :-))
as i started a bash after i defined the prompt in ksh:
X[11]=”";X[1]=’~';PS1=’[${X[1${PWD%%!(${HOME}*)}1]}${PWD#${HOME}}] ‘
i got very serius problems!! :-) (laughing!!!)
do you have any idea ot prevent this?
Greetings
Karl
Ps.: tested on AIX