title: Module files don't return non-zero exit codes to bash if the module fails to load. How can you make a conditional in bash with that?
body: <p>I'm new here, so I apologize in advance if I'm not following the protocol, but the message said to ask a new question. I had asked an earlier question: <a href="https://stackoverflow.com/questions/60310477/how-can-a-bash-script-try-to-load-one-module-file-and-if-that-fails-load-anothe">How can a bash script try to load one module file and if that fails, load another?</a>, but it is not a duplicate of <a href="https://stackoverflow.com/questions/49849957/bash-conditional-based-on-exit-code-of-command">Bash conditional based on exit code of command</a> as marked.</p>
  
  <p>The reason is that the module load  does not return a non-zero exit code if it fails to load. These are the <a href="http://modules.sourceforge.net/" rel="nofollow noreferrer">Environment Modules</a> that I am trying to use.</p>
  
  <p>For example,</p>
  
  <pre><code>#!/bin/bash
  
  if module load fake_module; then
      echo "Should never have gotten here"
  else
      echo "This is what I should see."
  fi
  </code></pre>
  
  <p>results in </p>
  
  <pre><code>ModuleCmd_Load.c(213):ERROR:105: Unable to locate a modulefile for 'fake_module'
  Should never have gotten here
  </code></pre>
  
  <p>How can I attempt to load <code>fake_module</code> and if that fails attempt to do something else? This is specifically in a <code>bash</code> script. Thank you!</p>
  
  <p>Edit: I want to be clear that I don't have the ability to modify the module files directly.</p>