2010/10/20

[Linux] PATH に重複したパスが登録される

環境は,Fedora13、csh です.

設定ファイル (.cshrc とか) でPATH に登録してパスを通すのはいいのだが,何回も読み込まれてるのか,重複して登録されている.特にそのままでも害はないのだが,さすがに長くなりすぎて嫌なので修正.

BASHでは,/etc/profile, /etc/login にある pathmunge 関数を使えばよさそう.
だが,CSHでは関数がないので,下記のようにする.

/etc/profile.d/pathmunge.csh-inc というファイルを作る.内容は下記.
foreach pathmunge_i (${path:q})
if ( "$pathmunge_i" == "$1" ) then
exit
endif
end
unset pathmunge_i

if ( "$2" == "after" ) then
set path = ( ${path:q} ${1:q} )
else
set path = ( ${1:q} ${path:q} )
endif

PATHに追加したいときは,
source /etc/profile.d/pathmunge.csh-inc /path/to/something/bin
とする.after をつければ後ろに追加される.

参考:
https://bugzilla.redhat.com/show_bug.cgi?id=544652