bash linux bash脚本中的模块加载命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45224536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
module load command in linux bash script
提问by skwang
I need to execute Python script in HPC cluster. Unfortunately, the default python version is just 2.6.6 and there is no numpy and scipy.
我需要在 HPC 集群中执行 Python 脚本。不幸的是,默认的 python 版本只有 2.6.6,没有 numpy 和 scipy。
I can load these modules in command line
我可以在命令行中加载这些模块
#module load /home/hw1u16/modules/2.7.3
and
和
module load /home/hw1u16/modules/1.6.2
However, when I write the bash script like this
但是,当我像这样编写 bash 脚本时
module load /home/hw1u16/modules/2.7.3
module load /home/hw1u16/modules/1.6.2
python /home/hw1u16/project/trainAgent.py
It warns me
它警告我
ModuleCmd_Load.c(200):ERROR:105: Unable to locate a modulefile for '/home/hw1u16/modules'
ModuleCmd_Load.c(200):ERROR:105: Unable to locate a modulefile for '/home/hw1u16/modules'
I don't know what's wrong, could any guys help me?
ModuleCmd_Load.c(200):ERROR:105: Unable to locate a modulefile for '/home/hw1u16/modules'
ModuleCmd_Load.c(200):ERROR:105: Unable to locate a modulefile for '/home/hw1u16/modules'
不知道怎么回事,有大佬帮帮我吗?
回答by DavidC.
Okay, I think I know where is the problem. Try type module
from the shell to see how module
it is currently defined in your system. You will receive two options: either it is an alias or a function. This is because the module
command is an alias
or shell function
.
好的,我想我知道问题出在哪里了。type module
从 shell尝试查看module
它当前在您的系统中是如何定义的。您将收到两个选项:别名或函数。这是因为module
命令是一个alias
or shell function
。
Say your script is the following running.sh
:
说你的脚本如下running.sh
:
#!/bin/bash
module load python/2.7.3
python /home/hw1u16/project/trainAgent.py
(It is a good practice to add the shebang)
(添加shebang是一个很好的做法)
To sort out this problem you have two options:
要解决此问题,您有两种选择:
- Option 1:
- 选项1:
source
the scitpt. In other words, do: source running.sh
. This is exactly the same as typing the module
command directly into your interactive shell. However, by doing ./running.sh
, you are running a new, non-interactive shell. These generally do not have the standard aliases and shell functions set up.
source
脚本。换句话说,做:source running.sh
。这与module
直接在交互式 shell 中键入命令完全相同。但是,通过执行./running.sh
,您正在运行一个新的非交互式 shell。这些通常没有设置标准别名和 shell 函数。
- Option 2:
- 选项 2:
Find the initialization script that defines the module
command and source
it from the script
从脚本中找到定义module
命令和source
它的初始化脚本
回答by Christian Seitz
I had a similar problem, and found two solutions:
我遇到了类似的问题,并找到了两个解决方案:
instead of running your script with
sh yourscript.sh
or./yourscript.sh
, you could run it as. yourscript.sh
This will source the module correctly and run the scriptif you don't want to use
. yourscript.sh
, you can modify your shebang from#!/bin/sh
to#!/bin/bash
as noted in DavidC's answer and run your script as./yourscript.sh
Note that running it assh yourscript.sh
will not work
而不是使用
sh yourscript.sh
或运行您的脚本./yourscript.sh
,您可以运行它,因为. yourscript.sh
这将正确获取模块并运行脚本如果您不想使用
. yourscript.sh
,您可以按照 DavidC 的回答中所述将您的shebang 修改为#!/bin/sh
to#!/bin/bash
并按以下方式运行您的脚本./yourscript.sh
请注意,按以下方式运行是sh yourscript.sh
行不通的