-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdelpath.pl
executable file
·70 lines (70 loc) · 1.49 KB
/
delpath.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env perl
#
# delete element from path
#
$pathtype = "PATH"; # the default path type
$shell = "C"; # the default shell
#
# process command line options
#
@token = ();
$this = shift;
while ($this) {
if ($this =~ m/^-/) {
if ($this eq '-l') {
$pathtype = "LD_LIBRARY_PATH";
} elsif ($this eq '-p') {
$pathtype = "PYTHONPATH";
} elsif ($this eq '-b') {
$shell = "Bourne";
} else {
die "bad command option: $this";
}
} else {
#print STDERR "delete $this\n";
push (@token, ($this));
}
$this = shift;
}
$line=$ENV{$pathtype};
#print STDERR "$line\n";
#
# escape special characters
#
$line =~ s/ /\\ /g; # blank
$line =~ s/\(/\\\(/g; # open parenthesis
$line =~ s/\)/\\\)/g; # close parenthesis
@field = split(/:/,$line);
#print STDERR "number of fields - 1 = $#field\n";
#print STDERR "number of fields to delete - 1 = $#token\n";
if ($#field == -1) {
if ($shell eq "C") {
print "unsetenv $pathtype\n";
} else {
print "unset $pathtype\n";
}
} else {
$newpath = "";
for ($j = 0; $j <= $#field ; $j++) {
$path = $field[$j];
#print STDERR "$j $path\n";
$keep = 1;
for($i = 0; $i <= $#token; $i++) {
#print "$i $token[$i]\n";
if ($path eq $token[$i]) {
$keep = 0;
}
}
if ($keep) {
#print STDERR "keep it\n";
if ($newpath ne "") {$newpath = $newpath . ":"}
$newpath = $newpath . $path;
}
}
if ($shell eq "C") {
print "setenv $pathtype $newpath\n";
} else {
print "export $pathtype=$newpath\n";
}
}
exit