1

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?

3 Answers3

4

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.

zega
  • 159
  • 1
  • 4
1

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.

eduffy
  • 39,140
  • 13
  • 95
  • 92
  • Thanks for the quick response, but something like the below isn't working: adm@mach:~> cat test1.sh #!/bin/bash source /etc/profile shopt -s expand_aliases module load MySQL #do stuff with mysql adm@mach:~> ./test1.sh ./test1.sh: line 6: module: command not found –  Jul 14 '09 at 19:32
  • adm@mach:~> cat test1.sh #!/bin/bash source /etc/profile shopt -s expand_aliases module load MySQL #do stuff with mysql adm@mach:~> ./test1.sh ./test1.sh: line 6: module: command not found –  Jul 14 '09 at 19:35
  • What about changing your first line to "/bin/bash -l"? – eduffy Jul 14 '09 at 20:04
-1

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

idupree
  • 730
  • 5
  • 16
  • catamount was talking about [Environment Modules](https://en.wikipedia.org/wiki/Environment_Modules_%28software%29) – Mark Booth Feb 08 '17 at 17:20