autodataming的个人博客分享 http://blog.sciencenet.cn/u/autodataming

博文

去除linux中PATH变量中冗余路径

已有 4235 次阅读 2018-12-26 12:27 |系统分类:科研笔记

在.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



https://wap.sciencenet.cn/blog-950202-1153624.html

上一篇:sudo 重定向权限问题
下一篇:pdb2gmx 命令使用注意事项
收藏 IP: 202.127.19.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-17 00:56

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部