Changes to environment variables are only passed down to child processes in Unix. Therefore, without taking some special steps, any changes your Perl program makes to your environment won't be reflected back to the calling shell program. A typical way to do something like this is to have your program output a bash command on its stdout, and eval that in bash.

For example, your bash line in .profile or .bashrc would be:eval `path_munch.pl`where the basic structure of path_munch.pl (bad name, I know) is:

#! /usr/bin/perl -w my @newpath; foreach (split /:/, $ENV{PATH}) { push @newpath, ... # however you do this } print 'export PATH=', join(':', @newpath), "\n";
(Note, this is untested code).

HTH


In reply to Re: Script to change $ENV{PATH} by VSarkiss
in thread Script to change $ENV{PATH} by gri6507

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.