Domain/Linux
[Linux][Shell] Cleaning PATH environment variable.
yhcting
2011. 9. 15. 11:04
With using terminal for a long time, PATH variable tends to be longer and longer due to duplicated path.
Here is simple sample script - with Perl - to resolve this.
# remove duplication at give PATH-format-string unique_path() { perl -w -e ' my %path_hash; exit unless (defined $ARGV[0]); foreach $p (split (/\:/, $ARGV[0])) { unless (defined $path_hash{$p}) { $path_hash{$p} = 1; push @newpath, $p; } } print join ":", @newpath; ' $1 } ...(skip)... PATH=$(unique_path "$PATH") ...(skip)
Done :-).