【问题标题】:alias does not work after qsubqsub 后别名不起作用
【发布时间】:2014-01-05 12:37:48
【问题描述】:

我在我的主文件夹下安装了 R,我想使用新的 R 在我向集群提交作业时被调用。集群节点都安装了 CentOS。

这是我在 .bash_profile 和 .bashrc 中所做的配置:

if [ `lsb_release -i|cut -c17-20` == 'Cent' ] ; then
    alias R='/home/XXX/R-3.0.2/bin/R'
    alias Rscript='/home/XXX/R-3.0.2/bin/Rscript'
fi

我在 .bash_profile 中添加了以下内容:

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

我还将它添加到提交的脚本中。

source $HOME/.bash_profile

我用 qsub -I 试过了,效果很好。

但是,在我提交作业后,which R 仍然显示原来的路径!

如何正确设置环境?

【问题讨论】:

    标签: r bash qsub


    【解决方案1】:

    别名不会影响which 命令,例如:

    $ which R
    /usr/bin/R
    $ alias R=/bin/date
    $ R
    Sun Jan  5 13:40:54 CET 2014      # as you see the alias works
    $ which R                         # `which R` still returns the original path
    /usr/bin/R
    

    我认为您不想使用别名,而是想将 /home/XXX/R-3.0.2/bin 添加到 PATH:

    PATH="/home/XXX/R-3.0.2/bin:$PATH"
    

    在此之后,如果R和Rscript存在于/home/XXX/R-3.0.2/bin中,那么:

    • which R 应该返回 /home/XXX/R-3.0.2/bin/R
    • which Rscript 应该返回 /home/XXX/R-3.0.2/bin/Rscript

    因为它们将首先在 /home/XXX/R-3.0.2/bin 中找到,然后在 $PATH 的其余部分中的任何其他目录中找到。

    【讨论】:

    • 谢谢@janos。我制作了一个 .env 文件并在其中添加了 PATH="/home/XXX/R-3.0.2/bin:$PATH" ,然后在 if 命令中检测到 CentO 时获取该文件。
    猜你喜欢
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 2012-12-17
    • 2015-01-28
    • 2012-07-19
    • 1970-01-01
    相关资源
    最近更新 更多