in reply to how to set environment vars

sh scripts can only "source" sh scripts.
csh scripts can only "source" csh scripts.
Perl scripts can only "source" Perl scripts.

What we can do is have the run csh script and output its env variables in an easily parsable format. env can help us here. In fact, it can even be done without modifying the csh script — let's call it "script.csh" — using the following Perl code:

my $env = `csh -c 'source script.csh; env'`; foreach my $line (split("\n", $env)) { my ($key, $val) = split('=', $line, 2); $ENV{$key} = $val; }

Updated: I simplified my post by inlining the "wrapper script" into the executed command.

Updated: Added the closing backtick that was accidently deleted.

Replies are listed 'Best First'.
Re^2: how to set environmental vars
by rsennat (Beadle) on Nov 10, 2005 at 21:03 UTC
    I did not get your idea on using a wrapper script... can you please explain a bit more...

      I realized my post was hard to read so I updated it. I even removed the need for a wrapper script. Does that help?
        Hi Ikegami,

        I tried your code and it works fine in the command line.

        But now I want this to get set the ENV vars in the browser, when I run the perl/cgi script.

        Any Idea on how to set env vars for the browser when running the perl/cgi scripts??

        Thanks
        rsennat