Re: manipulating PS1 in sh
2006-10-30 <1162217283.682259.169560@b28g2000cwb.googlegroups .com>,
EdStevens wrote:
>
> 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>
>>
>>
>> Regards
>> Dimitre
>
> 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
echo "$ORACLE_SID"
db02
Now, of course - it still won't change when you update it... you'd
probably need to make an alias to do that.
PS1_SRC='`hostname`.$ORACLE_SID>'
alias ps1upd=eval\ echo\ PS1=\\\"\\\'\$PS1_SRC\\\'\\\"
# Has to expand $PS1_SRC in double quotes outside the eval while
# putting it in single quotes inside the eval.
Actually, from my understanding of quoting rules this shouldn't work -
and I don't have a real sh to test it on, so if it doesn't work let me
know and i'll figure something else out. Then again it might work - i
don't really understand eval so this might be some obscure case that
makes it work.
(btw - you would not believe how many tries it took to get the quoting
right on that.) now call ps1upd whenever the hostname or ORACLE_SID
changes, feel free to add other stuff, etc. You can put anything in
PS1_SRC that you could put in a ksh prompt.
|