|
在.bashrc中添加路径到变量PATH中
每次执行source .bashrc会重复添加。
echo $PATH
把下面这段代码放到.bashrc文件的末尾,会删除冗余路径。
#!/bin/bash
#
# path-cleanup
#
# This must be run as "source path-cleanup" or ". path-cleanup"
# so the current shell gets the changes.
pathlist=`echo $PATH | sed 's/:/\n/g' |sort| uniq`
# echo "Starting PATH: $PATH"
# echo "pathlist: $pathlist"
unset PATH
# echo "After unset, PATH: $PATH"
for dir in $pathlist
do
if test -d $dir ; then
if test -z $PATH; then
PATH=$dir
else
PATH=$PATH:$dir
fi
fi
done
export PATH
# echo "After loop, PATH: $PATH"
#### 参考
https://stackoverflow.com/questions/11650840/remove-redundant-paths-from-path-variable
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 09:11
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社