如何删除shell的搜索路径?

sh/bash/dash/ksh/zsh等Shell脚本
回复
mecho
帖子: 13
注册时间: 2009-06-24 11:29

如何删除shell的搜索路径?

#1

帖子 mecho » 2009-07-05 13:12

新手的问题。

今天看教程可以用 export PATH=~/bin:$PATH 命令来增加shell的搜索路径。

那我想删除其中一个搜索路径,应该怎么做呢?
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 如何删除shell的搜索路径?

#2

帖子 eexpress » 2009-07-05 13:19

删除不能借用现有变量,那就列举罗。
● 鸣学
mecho
帖子: 13
注册时间: 2009-06-24 11:29

Re: 如何删除shell的搜索路径?

#3

帖子 mecho » 2009-07-05 13:22

列举?能详细说明一下吗?
头像
HuntXu
帖子: 5776
注册时间: 2007-09-29 3:09

Re: 如何删除shell的搜索路径?

#4

帖子 HuntXu » 2009-07-05 13:48

就是export PATH=原来的$PATH去掉你要删除的那个...
HUNT Unfortunately No Talent...
mecho
帖子: 13
注册时间: 2009-06-24 11:29

Re: 如何删除shell的搜索路径?

#5

帖子 mecho » 2009-07-05 17:28

理解了楼上的意思,
比如,现在的$PATH值为:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
当我想删除/usr/games路径时,可以通过:
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
来实现。

可是现在我知道$PATH值为:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
如何删除/usr/games呢?

大家帮忙写个完整的示例出来,谢了!
头像
chenfengyuan的马甲
帖子: 25
注册时间: 2009-07-06 7:57

Re: 如何删除shell的搜索路径?

#6

帖子 chenfengyuan的马甲 » 2009-07-06 8:19

mecho 写了:理解了楼上的意思,
比如,现在的$PATH值为:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
当我想删除/usr/games路径时,可以通过:
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
来实现。

可是现在我知道$PATH值为:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
如何删除/usr/games呢?

大家帮忙写个完整的示例出来,谢了!
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``#'' case) or the longest matching pattern (the ``##'' case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``%'' case) or the longest matching pattern (the ``%%'' case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter/pattern/string}
${parameter//pattern/string}
The pattern is expanded to produce a pattern just as in pathname expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string. In the first form, only the first match is replaced. The second form causes all matches of pattern to be replaced with string. If pattern begins with #, it must match at the beginning of the expanded value of parameter. If pattern begins with %, it must match at the end of the expanded value of parameter. If string is null, matches of pattern are deleted and the / following pattern may be omitted. If parameter is @ or *, the substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list.
头像
chenfengyuan的马甲
帖子: 25
注册时间: 2009-07-06 7:57

Re: 如何删除shell的搜索路径?

#7

帖子 chenfengyuan的马甲 » 2009-07-06 8:20

manpage里有
mecho
帖子: 13
注册时间: 2009-06-24 11:29

Re: 如何删除shell的搜索路径?

#8

帖子 mecho » 2009-07-06 17:56

回6楼: :em06 那是些啥东西?

回7楼:manpage是什么?是不是论坛上面的wiki?
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

Re: 如何删除shell的搜索路径?

#9

帖子 BigSnake.NET » 2009-07-06 19:07

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
chenfengyuan的马甲
帖子: 25
注册时间: 2009-07-06 7:57

Re: 如何删除shell的搜索路径?

#10

帖子 chenfengyuan的马甲 » 2009-07-07 9:22

mecho 写了:回6楼: :em06 那是些啥东西?

回7楼:manpage是什么?是不是论坛上面的wiki?
export PATH=${PATH%:/usr/games} #没试过,看man照着写的。不过,不建议你删除,还是直接export PATH=.....比较好,因为我不知道什么好的方法,那个不安全。可能回把类似于/usr/games/lib(如果有的话)的改成/lib。
在终端里man bash
回复