PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > manipulating PS1 in sh
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

manipulating PS1 in sh

Réponse
 
LinkBack Outils de la discussion
Vieux 27/10/2006, 21h06   #1
EdStevens
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut manipulating PS1 in sh

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)?

  Réponse avec citation
Vieux 27/10/2006, 21h44   #2
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: manipulating PS1 in sh

> 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


  Réponse avec citation
Vieux 28/10/2006, 04h21   #3
Jordan Abel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: manipulating PS1 in sh

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?
  Réponse avec citation
Vieux 30/10/2006, 13h58   #4
EdStevens
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: manipulating PS1 in sh


Jordan Abel wrote:
> 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.


Ah, but it does legitimately change quite often .. at my direction.
See my final comment, below.
>
> > 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?


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.

  Réponse avec citation
Vieux 30/10/2006, 14h08   #5
EdStevens
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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>
>
>
> 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

  Réponse avec citation
Vieux 30/10/2006, 14h49   #6
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: manipulating PS1 in sh

>> > 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


  Réponse avec citation
Vieux 30/10/2006, 18h21   #7
Jordan Abel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 30/10/2006, 18h33   #8
EdStevens
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.

  Réponse avec citation
Vieux 30/10/2006, 19h41   #9
Jordan Abel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: manipulating PS1 in sh

2006-10-30 <1162233231.589401.149050@i42g2000cwa.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>

>> [...]
>> > 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.


So there isn't _anything_ else on the system where you're forced to use
sh? not bash, not zsh, not anything?
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,23045 seconds with 17 queries