|
Home > Archive > Unix Shell > October 2006 > manipulating PS1 in sh
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
manipulating PS1 in sh
|
|
| EdStevens 2006-10-27, 7:15 pm |
| 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".
The simple solution is to simply run ksh (my preference) but that
presents certain, uh, political challenges. Is there a simple way of
achieving this same functionality under sh (Solaris 5.9)?
| |
| Radoulov, Dimitre 2006-10-27, 7:15 pm |
| > 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
| |
| Jordan Abel 2006-10-28, 1:30 am |
| 2006-10-27 <1161979585.383055.236660@e3g2000cwe.googlegroups.com>,
EdStevens 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".
$ORACLE_SID isn't going to change on you in the middle of a session
unless you eval something that explicitly changes it.
> The simple solution is to simply run ksh (my preference) but that
> presents certain, uh, political challenges. Is there a simple way of
> achieving this same functionality under sh (Solaris 5.9)?
Under what circumstances does this change?
| |
| EdStevens 2006-10-30, 1:19 pm |
|
Jordan Abel wrote:
> 2006-10-27 <1161979585.383055.236660@e3g2000cwe.googlegroups.com>,
> EdStevens wrote:
>
> $ORACLE_SID isn't going to change on you in the middle of a session
> unless you eval something that explicitly changes it.
Ah, but it does legitimately change quite often .. at my direction.
See my final comment, below.
>
>
> Under what circumstances does this change?
That variable is used by Oracle to designate the 'current default'
database, allowing a simpler 'connect' command -- not having to specify
a lengthy connect string that explicitly states which database I want
to work with. Quite handy on a system that is hosting multiple
databases.
| |
| EdStevens 2006-10-30, 1:19 pm |
|
Radoulov, Dimitre wrote:
> [...]
>
> $ 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
| |
| Radoulov, Dimitre 2006-10-30, 1:19 pm |
| >> > Trying to set PS1 to reflect the current value of a user environment
[...][vbcol=seagreen]
> 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
| |
| Jordan Abel 2006-10-30, 1:19 pm |
| 2006-10-30 <1162217283.682259.169560@b28g2000cwb.googlegroups.com>,
EdStevens wrote:
>
> Radoulov, Dimitre wrote:
>
> 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.
| |
| EdStevens 2006-10-30, 1:19 pm |
|
Radoulov, Dimitre wrote:
> [...]
>
>
> 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.
| |
| Jordan Abel 2006-10-30, 7:30 pm |
| 2006-10-30 <1162233231.589401.149050@i42g2000cwa.googlegroups.com>,
EdStevens wrote:
>
> Radoulov, Dimitre wrote:
>
> 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.
So there isn't _anything_ else on the system where you're forced to use
sh? not bash, not zsh, not anything?
|
|
|
|
|