Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Unix question: how to display SID and path in prompt

RE: Unix question: how to display SID and path in prompt

From: Curiel, David <david.curiel_at_pioneer.com>
Date: Mon, 26 Aug 2002 12:03:20 -0800
Message-ID: <F001.004BFC1A.20020826120320@fatcity.com>


Jared Writes:
>> Also be aware that when using backticks in your PS1 variable, you are
>> influencing $? as a result.

>I don't find that to be true with pdksh - PD KSH v5.2.14 99/07/13.2



That would be because in your example, PS1 is only being affected when you actually do a 'cd'
In my case, (and I think that of the original poster), PS1 is being specified in the main body of my bash/ksh rc file, in which case it is evaluated every time you do any/every command.

Your example is certainly more efficient, in that your the PATH information is only updated when your current directory is likely to have changed, but I actually echo every command's $? onto my prompt. i.e my prompt looks like:

RC(1) azimuth:.../last_2/path_components$

Actually, I had to create a function to do this, so that $? was properly returned.

function _cd {

        typeset  saverc=$?
        typeset _path=`echo $PWD | sed
'/\/.*\/.*\//{s%.*/\(.*/.*\)%.../\1%;}' `
        echo "RC($saverc) $HOST:$_path\$ "
        return $saverc

}
PS1='`_cd`'

Otherwise if you are simply setting PS1 with backticks in the main() of your rc file, then your $? is hosed.
At least as far as I've experienced....

Thanks
David

-----Original Message-----
Sent: Monday, August 26, 2002 12:58 PM
To: ORACLE-L_at_fatcity.com
Cc: Curiel, David

> Also be aware that when using backticks in your PS1 variable, you are
> influencing $? as a result.

I don't find that to be true with pdksh - PD KSH v5.2.14 99/07/13.2

function go {

   \cd $1

   typeset -Z2 _h; typeset -Z2 _m                  # 2 digits, zero padded
   _hh="(SECONDS/3600)%24" _mm="(SECONDS/60)%60" # hours, minutes    _time='${_x[(_m=_mm)==(_h=_hh)]}$_h:$_m'    typeset bold=$(tput bold)
   typeset shy=$(tput rmso)
   PS1="[ `pwd` ]"
   PS1=$PS1`echo
"\n\n${bold}$_time-${UMACHINE}:${ORACLE_SID}${shy}:${LOGNAME}-$TTY > "`

   # need to be able to turn xtitle off when using 'go'    if [ "$TERM" = "xterm2" -o "$TERM" = "xterm" ] ;then

      # don't do xtitle if NO_CD_TITLE is set or in SCREEN
      #[ "$NO_CD_TITLE" -o "$WINDOW" -ge 1 ] || xtitle ${MACHINE}:${PWD}
      :

   fi
}

alias cd='go '



10:2-rsysdevdb:dv01:jkstill-3 > rm this_file_does_not_exist rm: cannot remove `this_file_does_not_exist': No such file or directory [ /home/jkstill/tmp ]

10:2-rsysdevdb:dv01:jkstill-3 > echo $?
1
[ /home/jkstill/tmp ]

10:2-rsysdevdb:dv01:jkstill-3 > echo $?
0
[ /home/jkstill/tmp ]

10:2-rsysdevdb:dv01:jkstill-3 >

Jared

"Curiel, David" <david.curiel_at_pioneer.com> Sent by: root_at_fatcity.com
08/26/2002 08:23 AM
Please respond to ORACLE-L  

        To:     Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>
        cc: 
        Subject:        RE: Unix question: how to display SID and path in
prompt

Also be aware that when using backticks in your PS1 variable, you are influencing $? as a result.  

What happens, is that when you run a command (i.e. "rm <some_file_that_doesnt_exist>") and then say "echo $?", you are getting the
return code ($?) of your PS1 execution (which is likely to always be 0) - NOT the $? of the "rm" command.  

David Curiel  

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Curiel, David
  INET: david.curiel_at_pioneer.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Mon Aug 26 2002 - 15:03:20 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US