Bash $ PATH会缓存每个修改 [英] Bash $PATH is caching every modification
问题描述
如何清除BASH中$ PATH的缓存.每次我修改$ PATH时,以前的修改也会保存下来!因此,我的$ PATH已经是一个页面了:-),它困扰着我,因为它指向了一些不合适的地方(因为每次修改都被附加在$ PATH变量的末尾).请帮我解决这个问题.
How to clear the cache of $PATH in BASH. Every time I modify the $PATH, the former modifications are conserved too! So my $PATH is already one page :-), and it bothers me to work, because it points to some not right places (because every modification is being appended in the end of the $PATH variable). Please help me to solve this problem.
推荐答案
因为每个修改都在进行中 附加在$ PATH的末尾 变量
because every modification is being appended in the end of the $PATH variable
仔细查看您在哪里设置$PATH
,我敢打赌它看起来像这样:
Take a close look at where you are setting $PATH
, I bet it looks something like this:
PATH="$PATH:/some/new/dir:/another/newdir:"
在新作业中具有$PATH
,可为您提供不需要的附加行为.
Having $PATH
in the new assignment gives you the appending behavior you don't want.
相反,这样做:
PATH="/some/new/dir:/another/newdir:"
更新
如果要删除所有重复条目的$PATH
,但仍保持原始顺序,则可以执行以下操作:
Update
If you want to strip $PATH
of all duplicate entries but still maintain the original order then you can do this:
PATH=$(awk 'BEGIN{ORS=":";RS="[:\n]"}!a[$0]++' <<<"${PATH%:}")
这篇关于Bash $ PATH会缓存每个修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!