in reply to Script to change $ENV{PATH}

Hi,
The solution proposed by VSarkiss is interesying, but it has two drawbacks. First, it only applies to bash or sh, and second, does not generalize to other PATH like variables. I think this one solves these problems.

This gives the following under bash:

$ TEST="a:b:c:a:c:z:a:b:z" $ echo $TEST a:b:c:a:c:z:a:b:z $ TEST=`tmp/test.pl $TEST` $ echo $TEST a:z:b:c
and the following under csh:
> setenv TEST "a:b:c:a:c:z:a:b:z" > echo $TEST a:b:c:a:c:z:a:b:z > setenv TEST `tmp/test.pl $TEST` > echo $TEST a:z:b:c

Hope that helps....

Cheers


Leo TheHobbit

Replies are listed 'Best First'.
Re: Re: Script to change $ENV{PATH}
by TheHobbit (Pilgrim) on May 08, 2003 at 10:02 UTC

    Argh.... I'm stupid today:) There is a big mistake in my post...

    The component order in PATH-like variables is important, sometimes very important, and my munch.pl script mess it up. This version of munch.it don't has this pitfall:

    #!/usr/bin/perl -w use strict; my @comp = split /:/,shift; my %saw = (); my @out = (); for (@comp) { push @out,$_ unless $saw{$_}++; } print join ":",@out;

    Now I may gonna hide in the monastery cellar...


    Leo TheHobbit