问题
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?
回答1:
Start your bash script like this:
#!/bin/bash -l
Note that modules loaded after this with module load xyz will only be available from inside the script file.
回答2:
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.
回答3:
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.
(For example, I don't even have a module
command on my distro/setup, so I can't try it to see what kind of modules you're referring to.)
来源:https://stackoverflow.com/questions/1127383/how-to-issue-module-load-in-a-shell-or-perl-script-i-e-non-interactively