bash 如何在 shell 或 Perl 脚本中发出“模块加载”(即,非交互式)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1127383/
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
How to issue "module load" in a shell or Perl script (i.e., non-interactively)
提问by zega
I can use the "module load xyz" command interactively, but when run from a script, it says it can't find the "module" command. Is there any way of loading modules in a script?
我可以交互地使用“module load xyz”命令,但是当从脚本运行时,它说它找不到“module”命令。有没有办法在脚本中加载模块?
回答by zega
Start your bash script like this:
像这样启动你的 bash 脚本:
#!/bin/bash -l
#!/bin/bash -l
Note that modules loaded after this with module load xyz will only be available from inside the script file.
请注意,在此之后使用 module load xyz 加载的模块只能从脚本文件内部使用。
回答by eduffy
Try
尝试
source /etc/profile
If that doesn't work, you most likely have a problem with aliases. You may need
如果这不起作用,则很可能是别名有问题。你可能需要
shopt -s expand_aliases
in your script.
在你的脚本中。
回答by idupree
If by modules you mean Linux kernel modules, look into modprobe(or the more low-level insmod). There's usually no need to use whatever aliases (like module) that your Linux distro loaded into your shell.
如果模块是指 Linux 内核模块,请查看modprobe(或更底层的insmod)。通常不需要使用moduleLinux 发行版加载到 shell 中的任何别名(如)。
(For example, I don't even have a modulecommand on my distro/setup, so I can't try it to see what kind of modules you're referring to.)
(例如,我什至没有module关于我的发行版/设置的命令,所以我无法尝试查看您所指的模块类型。)

