Dup Ver Goto 📝

TidyPath

PT2/aw/lang/perl does not exist
To
38 lines, 93 words, 585 chars Page 'TidyPath' does not exist.

For removing duplicates from the PATH variable, and for adding new entries. For example

tidypath a:b:c b:c d:e:f:a

will output

a:b:c:d:e:f
#!/usr/bin/perl

@p = ();
%p = ();

for(@ARGV) {
  if( /^-p/ ) {
    @a = split ":", $ENV{'PATH'};
    for $a(@a) {
      if( ! $p{$a} ) {
        push @p, $a;
        $p{$a} = 1;
      }
    }
  } else {
    @a = split ":";
    for $a(@a) {
      if( ! $p{$a} ) {
        push @p, $a;
        $p{$a} = 1;
      }
    }
  }
}

$path = join ":", @p;
print "$path\n";