Re: manipulating PS1 in sh




Radoulov, Dimitre wrote:
Trying to set PS1 to reflect the current value of a user environment
variable, when running in sh.

Most of my systems I am running in ksh, and my PS is set as follows:

export PS1=`hostname`'.''$ORACLE_SID> '

so that my prompt always shows the current value of $ORACLE_SID. But
it appears that this syntax doesn't yeild the same results with sh.
There, instead of returning the value of $ORACLE_SID, it simply returns
the literal "$ORACLE_SID".
[...]

$ PS1=`hostname`'.''$ORACLE_SID> '
xxx.ora10gr2> sh
xxx.$ORACLE_SID> PS1="`hostname`.$ORACLE_SID>"
xxx.ora10gr2>
[...]
Which returns the LITERAL "$ORACLE_SID". I need the VALUE of the
ORACLE_SID variable, like this:

$> ORACLE_SID=db01
$> echo $ORACLE_SID
$> db01
$> PS1= "`hostname`'.'?????'>'
db01>
db01> ORACLE_SID=db02
db02> echo $ORACLE_SID
db02> db02


For sh you could define a function and use it to set the PS1:

setorasid() {
ORACLE_SID="$1"
PS1="$ORACLE_SID>"
export ORACLE_SID PS1
}

$ setorasid db01
db01>setorasid db02
db02>


Regards
Dimitre

Dimitre and Jordan,

thanks for tips. I'll play around with them and see how it goes. Of
course, since ksh will allow me to get the 'dynamic' setting of PS1
(with no other functions, etc. required) I was hoping that sh would as
well, albeit with some modifications to the syntax.

.



Relevant Pages

  • Re: manipulating PS1 in sh
    ... Most of my systems I am running in ksh, and my PS is set as follows: ... For sh you could define a function and use it to set the PS1: ... Dimitre and Jordan, ...
    (comp.unix.shell)
  • Re: [[ x -eq 1 ]]
    ... I see this behaviour in both bash and ksh, ... Is it a feature or bug? ... Dimitre ...
    (comp.unix.shell)