PS1 shell variable

B

bogdan_czyz

Hi All,

It looked like a simple thing... but apparently it's not... or I'm
missing something.
How to get PS1 shell setting for prompt from within Perl script.
I couldn't make it working neither with $ENV{PS1} not
Shell::EnvImporter ....
Any suggestions welcome.

Thanks,
Bogdan
 
U

usenet

I couldn't make it working neither with $ENV{PS1} not
Shell::EnvImporter ....

If you can
echo $PS1
then you should be able to
perl -e 'print $ENV{PS1}'

If you see something from that perl command but not from your script
then your script is not running under the same environment as your
shell (which sources your .bashrc or whatever). Maybe it's a CGI or a
forked process or something like that?
 
B

bogdan_czyz

I tried that already ....
If you run this like that nothing is returned .. at least on redhat ES4
.... that's why I got stuck ...
it works on AIX though .... really weird
 
U

usenet

If you run this like that nothing is returned .. at least on redhat ES4
it works on AIX though .... really weird

You're probably using ksh on AIX but bash on RH. Different shells;
different conventions.
 
U

Uri Guttman

u> You're probably using ksh on AIX but bash on RH. Different shells;
u> different conventions.

good catch. and i wonder why he cares about a shell prompt inside perl.
if he wants a standard prompt from the shell env, create a new one and
set it everywhere. fun!

uri
 
D

DJ Stunks

Uri said:
u> You're probably using ksh on AIX but bash on RH. Different shells;
u> different conventions.

good catch. and i wonder why he cares about a shell prompt inside perl.

WAG: some people use the definedness of PS1 to determine if they're
running in an interactive shell or not?

if I'm right then as I recall _PBP_ discussed how to determine if one
was operating interactively but I don't have my copy with me.

that's my meagre contribution to this thread :p

-jp
 
U

usenet

DJ said:
if I'm right then as I recall _PBP_ discussed how to determine if one
was operating interactively but I don't have my copy with me.

I don't recall it in _PBP_, but it's a FAQ:

perldoc -q interactive
How do I find out if I'm running interactively or not?
 
D

DJ Stunks

I don't recall it in _PBP_, but it's a FAQ:

perldoc -q interactive
How do I find out if I'm running interactively or not?

oh, right.

And I'm sure this is totally off topic, but just for posterity's sake,
Damian suggests

use IO::Interactive qw{ is_interactive };

if ( is_interactive() ) {
# ...

-jp
 
M

Mumia W. (reading news)

Hi All,

It looked like a simple thing... but apparently it's not... or I'm
missing something.
How to get PS1 shell setting for prompt from within Perl script.
I couldn't make it working neither with $ENV{PS1} not
Shell::EnvImporter ....
Any suggestions welcome.

Thanks,
Bogdan

PS1 would probably have to be exported first.

export PS1
 
E

ewfalor

Mumia said:
PS1 would probably have to be exported first.

export PS1

Agreed. I couldn't get this to work on any OS until I exported PS1.
It most likely works on AIX for you because your .<shell>rc file
exports it for some reason.
 
B

bogdan_czyz

Reason for that is rather trivial. I just wanted to have simple check
if prompt is configured to meet our standards. We usually modify system
prompt to show some additional info not just user@host and part of
path.

Bogdan
 
B

bogdan_czyz

But how to export PS1 from within PERL script? To export it you need to
have its value first.

Bogdan
 
U

Uri Guttman

bc> Reason for that is rather trivial. I just wanted to have simple check
bc> if prompt is configured to meet our standards. We usually modify system
bc> prompt to show some additional info not just user@host and part of
bc> path.


and how is this perl code called? if it is explicitly called from the
shell then you can pass in the supposed prompts and not worry about
using the env. as someone else pointed out, PS1 may be set in the shell
but not exported as who would normally export a prompt?

uri
 
B

bogdan_czyz

Script is supposed to get information from the system and verify that
server setup meets given requirements. One of requirements is system
prompt look. Passing variable with current system prompt is sort of
missing the point of that part of script. It's not very important but
since I wasted some time already I'd like to resolve it somehow.
Is there a way to source easy for instance /etc/bashrc or capture this
variable somewhere?

Thanks :)
Bogdan
 
U

Uri Guttman

bc> Script is supposed to get information from the system and verify
bc> that server setup meets given requirements. One of requirements is
bc> system prompt look. Passing variable with current system prompt is
bc> sort of missing the point of that part of script. It's not very
bc> important but since I wasted some time already I'd like to resolve
bc> it somehow. Is there a way to source easy for instance
bc> /etc/bashrc or capture this variable somewhere?

you haven't given any useful information. what is the 'system'? PS vars
are usually set in some .rc file so you have to locate those. and they
aren't exported by default in some shells. you have to come up with a
solid description of what you have (shell, platforms, .rc files, users,
etc.) and analyze what you have and need to do.

and STOP TOP POSTING.

uri
 
A

anno4000

Top-posting corrected. You have been asked not to do that.
But how to export PS1 from within PERL script? To export it you need to
have its value first.

This is so wrong, it hurts. You don't need the value of a shell
variable to export it, only its name. You can't export a shell
variable from a Perl (not PERL) script because there is no shell
running and hence no shell variable.

To find what value the shell variable PS1 is set to by standard,
run the appropriate shell from perl, let it echo the variable and
catch the output. There is no need to mess with exportation. This
has little to do with Perl.

Anno
 
I

Ingo Menger

Script is supposed to get information from the system and verify that
server setup meets given requirements. One of requirements is system
prompt look. Passing variable with current system prompt is sort of
missing the point of that part of script. It's not very important but
since I wasted some time already I'd like to resolve it somehow.

I'm afraid perl does not support fascistoid measures such as that. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top