johnsonyoung
【求助】怎样减少PATH中的变量?
由于PATH中的多个变量里可能存在名字相同的程序,我想去除其中一个变量,如
原来的PATH=/usr/bin,/usr/sbin
想变成PATH=/usr/bin的话应该怎么做?
谢谢各位热心帮助!
寂寞烈火
在/etc/profile中将[code]
pathmunge /usr/sbin[/code]
去掉试一试
志国
[quote]原帖由 [i]寂寞烈火[/i] 于 2008-1-9 20:43 发表 [url=http://linux.chinaunix.net/bbs/redirect.php?goto=findpost&pid=6444742&ptid=918580][img]http://linux.chinaunix.net/bbs/images/common/back.gif[/img][/url]
在/etc/profile中将
pathmunge /usr/sbin
去掉试一试 [/quote]
不知道高人的方法怎样!!!
关注!!!
要不就从新定义一个PATH的变量,写到~/.bash_profile中,只要不包括你不想要的路径就行了呗!
胡想的不知道成不成!!
johnsonyoung
谢谢各位帮助,找了一下在所用的操作系统中没有pathmunge这个命令,看来只能写一个脚本,以:分离开每个变量,如果变量等于要去除的变量就不拷贝,否则拷贝到新的PATH变量然后再export.
寂寞烈火
[quote]原帖由 [i]johnsonyoung[/i] 于 2008-1-10 09:45 发表 [url=http://linux.chinaunix.net/bbs/redirect.php?goto=findpost&pid=6444841&ptid=918580][img]http://linux.chinaunix.net/bbs/images/common/back.gif[/img][/url]
谢谢各位帮助,找了一下在所用的操作系统中没有pathmunge这个命令,看来只能写一个脚本,以:分离开每个变量,如果变量等于要去除的变量就不拷贝,否则拷贝到新的PATH变量然后再export. [/quote]
[code]
/etc/skel#cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}
# Path manipulation
if [ `id -u` = 0 ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi
pathmunge /usr/X11R6/bin after
unset pathmunge
[/code]