0

I have one script which determine the module load status.

In the following code Line 4, it give me error that it can not load specific version than after I have check the status. Ideally I should get 1 as a status But it was still zero.

Then I have check with command line also. Like module load her/2012;echo $status.

I could not understand why am I getting status code 0. More specific to issue, how can I determine the status of module load command

  1         #!/bin/csh -fe
  2         source /global/etc/csh.cshrc
  3         module unload hercules
  4         module load hercules/2012
  5         if ( $status != 0) then
  6          echo "Error: abhishek Unable to execute  module load hercules/2012"
  7          exit
  8         endif
user765443
  • 1,856
  • 7
  • 31
  • 56

2 Answers2

1

It is not documented that module sets the exit status appropriately. If it doesn't, you can still examine its output, like

module load hercules/2012 |& if ({ grep error }) then
    echo "Error: abhishek Unable to execute  module load hercules/2012"
    exit
endif
Armali
  • 18,255
  • 14
  • 57
  • 171
  • 1
    As deduced, `module` command did not return an appropriate exit code until recently. Should install environment-modules >= 4.0 to rely on exit code returned – Xavier Delaruelle Aug 06 '18 at 19:16
0

The problem is that in the first line of the script, csh is called with -fe. According to the man pages, the -e option of csh "causes the script to exit if any invoked command terminates abnormally or yields a non-zero exit status." Therefore, as soon as the script has an error, it terminates without going through the rest of the code in the script.

Therefore, try changing #!/bin/csh -fe to #!/bin/csh -f.

ZaSter
  • 1,192
  • 14
  • 20