On Dec 10, 2003, at 3:06 PM, drieux wrote:
On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote:

Is there a way using Perl to add to the environment
variable PATH a new path, and that addition will be
valid after the script is ran and not only for the script's scope.
I'm working in cshell in Solaris 5.8
[..]

Robert, Tom, thank you for the advice,
and the good intentions, but forgive me
if I go back over what I posted to
demonstrate a solution, complete with
executing it to perchance go back over
a series of basic issues.

The critical part of the OP's query is

"valid after the script is ran and not only for the script's scope"

Unfortunately this is almost FAQ country, since
almost every 'scripter' notices that it would be
cooler IF they could do something like that. But
they do not always think about which part of the
process they are really trying to 'fix'.

Both of you saved the 'demonstration' portion of my
response to the OP, where I tried to illustrate the
idea of what the OP seems to have been asking. But
without actually noting the portion of the live
run code:

        vladimir: 89:] echo $BOB
        BOB: Undefined variable
        vladimir: 90:] perl add_path
        vladimir% echo $BOB
        my bob here
        vladimir%

the prompt shifts from the 'cool' csh style defined in my .login as

set prompt="`Hostname`: \!:] "

back to a 'system default style' as

"vladimir%"

that occurred because the perl code:

vladimir: 91:] sed 's/^/### /' add_path
        ### #!/usr/bin/perl -w
        ### use strict;
        ###
        ### my $path = '/happy/place/here';
        ### $ENV{PATH} = $path . ":" . $ENV{PATH} ;
        ### $ENV{BOB} = "my bob here";
        ### exec("/usr/bin/csh -f");
        vladimir: 92:]

really does exec() a "csh" with the "-f" flag, so that the newly spawned shell will NOT go back and resource my .login and .cshrc files, so that the '$ENV{PATH} = $path . ":" . $ENV{PATH} ;' will pre-pend the value for all sub-sequent shells.

{ note, yes, we could expand that code to
        a. test that $path existed in the $ENV{PATH}
        b. if not then to update the .login/.cshrc as appropriate
        c. then exec ourselves
}

The point of this drill is three fold:

        a. IF the OP wanted to simply edit their
                .login and/or .cshrc file to fix the
                PATH line, then they have already been
                informed of that.
        { someone even was polite enough to point to
                one of the canonical FAQ's about this. }

        b. the problem of trying to execute a command in
                a shell that is, by it's very nature, being
                executed in a 'sub_shell' will be HARD PRESSED
                to go back and 'fix' the environment of the spawning shell
                irregardless of the nature of the coding language used.

        { since technically the 'environment' is part of the process
                space information, there is merely the issue of gaining
                access to that information and bit twiddling it.

Not something I will advocate while sober. }

c. we all need to work on our reading and writing skills.

The perl add_path I hacked is derived from a much
older piece of ksh that I used:

vladimir: 62:] sed 's/^/### /' goMars
### #!/bin/ksh
###
### #
### # a way to play around in the Happy Mars Land Game
### #
###
### CommonDefFile=${HOME}/etc/drieuxTool.dfn
###
### if [ -f ${CommonDefFile} ]
### then
###         . ${CommonDefFile}
### else
###         echo "unable to find  ${CommonDefFile}"
###         exit
### fi
###
### PS="HappyMars > "
### export PS
### ENV=${HOME}/.mars.kshrc
### export ENV
###
### ksh
###
### exit
vladimir: 63:]

This way I could keep my default 'csh' login shell,
clean from all of that Foo CommonDefFile Definitions
as well as the ".mars.kshrc" set of ENV values, while
still giving me a 'work around' that would let me
flop into "mars" for doing certain types of work.

The reason I did not want to gobbledeGook up my
lovely .cshrc/.login file is that it is unpleasantly
bloated enough as it is so that it solves on the
fly which set of *nix ThingiePoos are in play based
upon the underlying type/version of *nix the file
is invoked on... { don't ask. MORE deep seated
unresolved cross platform compatibility issues.
Not to mention odd divergences within the linux
sub-cult of the *nix cults... }

Any Questions?

ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to