List Info

Thread: How to modify $ENV portably?




How to modify $ENV portably?
user name
2006-05-30 06:51:33
Hi,

The format of env variable PATH seems to change with
OS/shell. For example, 
in sh it is like 

"/dir1/bin:/dir2/bin:."

while in csh, it is like 

(/dir1/bin /dir2/bin .)

I need to search for "/dir2/bin" path component
in my
$ENV, and then, insert "/newpath/bin" just
before "/dir2/bin". But due to different format
of
PATHs in different os/shells, I am not able to do that
in a very clean way.

Is there any Perl Array (somewhat like INC)
which I
can modify to have my PATH changed?

Thanks,
Arijit


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 
_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Userslistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
How to modify $ENV portably?
user name
2006-05-30 07:54:10
Arijit Das wrote:

> Hi,
> 
> The format of env variable PATH seems to change with
> OS/shell. For example, 
> in sh it is like 
> 
> "/dir1/bin:/dir2/bin:."
> 
> while in csh, it is like 
> 
> (/dir1/bin /dir2/bin .)
> 
> I need to search for "/dir2/bin" path
component in my
> $ENV, and then, insert "/newpath/bin"
just
> before "/dir2/bin". But due to different
format of
> PATHs in different os/shells, I am not able to do that
> in a very clean way.
> 
> Is there any Perl Array (somewhat like INC)
which I
> can modify to have my PATH changed?

You're only modifying it for any child processes you
create,
so you could force the children to be spawned by one sh or
the other (tcsh/bash) or you could find the user's shell in
the /etc/passwd entry and use that one.

if ($shell =~ /^(?:ba)?sh$/) {
} elsif ...

You could check the existing PATH vrbl and see if it's
sh/bash or
csh/tcsh style path (' ' vs ':') and go accordingly.

_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Userslistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
How to modify $ENV portably?
user name
2006-05-30 14:03:10
Arijit Das wrote on 05/30/2006 02:51 AM:
> I need to search for "/dir2/bin" path
component in my
> $ENV, and then, insert "/newpath/bin"
just
> before "/dir2/bin".
> [...]
> Is there any Perl Array (somewhat like INC)
which I
> can modify to have my PATH changed?

Maybe this CPAN module can help you:

	http://sea
rch.cpan.org/~dsb/Env-Path-0.16/


As was previously said, any $PATH changes only affect child
processes.

	-Aleksandar
_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Userslistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )