zeus83 has asked for the wisdom of the Perl Monks concerning the following question:

Hello to all,
I have recently started with perl. Sorry for my English.
I have some Dupplicate in Path variable.(by the installation of some apps that you can see two identical addresse written in Path).
my goal is that I just change path and these changes may remain when I reboot system. I have a script with perl written that you can delete dupplicate but in the end I see it again. This means my script has no effect on Path enviroment variable.
how can I change that path variable so stay with the reboot the changes?
thank you for your help in advance
here is my code:

........for test........
#<<forTest $ENV{'PATH'}='/bin;/usr;/bin;/usr/local/bin:/home/fred/bin'; #<< or $t = $ENV{'PATH'}; @array=split(/;/,$t); # zeigt jede node vom array foreach (@array){ # print "$_\n"; } $flag = 0; for ($i=0;$i<@array.length;$i++) { for ($j=$i+1;$j<@array.length;$j++) { if (@array[$i] eq @array[$j]) { print "[", @array[$i], "]"; print " is equal to " ; print "[", @array[$j], "]"; print " index vom array : "; print $i ; print ","; print $j , "\n" ; @array[$i] = ''; $flag = 1 ; } } } if ($flag == 0) {print "no Duplicate :D \n";} foreach (@array){ # print "$_\n"; } print " old Path: \n"; print $ENV{'PATH'}; print " \n"; print " new Path: \n"; $TEMP = ''; for ($i=0;$i<@array.length;$i++) { if (@array[$i] eq '') {$TEMP = $TEMP . @array[$i] ;} else {$TEMP = $TEMP . @array[$i] . ';';} } $ENV{'PATH'} = $TEMP ; print $ENV{'PATH'}; print " \n";
............................
  • Comment on how I can with perl script change path variable so that the changes remain with the system reboot?
  • Download Code

Replies are listed 'Best First'.
Re: how I can change path variable so that the changes remain with the reboot?
by tobyink (Canon) on Jan 09, 2014 at 11:10 UTC

    That's not how environment variables work. Your Perl script gets a copy of your environment when it starts running. It can alter the environment all it wants, but it's only altering its own copy.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

      I used perl with Eclips and get error when using "use Moops;" my goal is that I just change path and these changes may remain when I reboot system

        "...remain when I reboot..."

        Yes shure. But your PATH is set in one of the configuration files of bash. See my first post. IMHO you need to figure out where it is set. This will also be the solution for eleminating possible duplicate entries in your PATH.

        And your PATH settings will only be persistent when you put them in one the bash configuration files

        Please see also bashrc (in german).

        Regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

        That sounds like you need to change not the PATH but the include path, so either or reinstall Moops so that it is in a "standard" location.
Re: how I can with perl script change path variable so that the changes remain with the system reboot?
by BrowserUk (Patriarch) on Jan 09, 2014 at 12:10 UTC

    Environment variables are like genes; copies are passed from parent to child.

    Whilst the child may modify (mutate) the copy it inherits, that will have no affect upon the parents copy.

    (To make permanent changes to the environment on Windows; you could look at Win32::TieRegistry, but that will still not affect the environment of existing (eg. parent) processes.)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      that sounds good ... maybe I can create a new variable and delete old ones.
      thank you
Re: how I can change path variable so that the changes remain with the reboot?
by karlgoethebier (Abbot) on Jan 09, 2014 at 11:41 UTC

    Please see also Bash Startup Files:

    "When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior."

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      Thank you all , I want to change only the contents of path with new content ($ TEMP, you can see it at the end of the code)
Re: how I can change path variable so that the changes remain with the reboot?
by 2teez (Vicar) on Jan 09, 2014 at 11:20 UTC

    You might have to check how to set up your path ( or edit it manually ) from your system setup.

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: how I can change path variable so that the changes remain with the reboot? (CleanPath)
by Anonymous Monk on Jan 09, 2014 at 11:26 UTC
      it looks complicated for me but I'll look at it.
      thank you already
        ooops, I completely missed the bashyness of the question -- these programs won't help much they're targetted at windows