External Email - Use Caution        

In a HPC cluster where freesurfer is loaded ad hoc as a module, running module avail results in the following warning:

/path/to/anaconda3-2021.11/bin/mpicc: line 285: x86_64-conda_cos6-linux-gnu-cc: command not found
 ERROR: Environment variable FREESURFER_HOME must be defined prior to sourcing Freesurfer.
/path/to/anaconda3-2021.11/bin/mpicc: line 285: x86_64-conda_cos6-linux-gnu-cc: command not found
 ERROR: Environment variable FREESURFER_HOME must be defined prior to sourcing Freesurfer.

I don't think ts related but here is my .bashrc file:

 >>> conda initialize >>>

 !! Contents within this block are managed by 'conda init' !!

__conda_setup="$('/path/to/anaconda3-2021.11/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"

if [ $? -eq 0 ]; then

    eval "$__conda_setup"

else

    if [ -f "/path/to/anaconda3-2021.11/etc/profile.d/conda.sh" ]; then

        . "/path/to/anaconda3-2021.11/etc/profile.d/conda.sh"

    else

        export PATH="/path/to/anaconda3-2021.11/bin:$PATH"

    fi

fi

unset __conda_setup


The modulefile for Freesurfer contains:

module-whatis "adds freesurfer to your environment variables"

set              root          /path/to/freesurfer

setenv    "FREESURFER_HOME"    "/path/to/freesurfer"

setenv    "SUBJECTS_DIR"      "/path/to/freesurfer/subjects"

prepend-path     PATH                 $root/bin

if { [ module-info mode load ] } {

system "source /path/to/freesurfer/SetUpFreeSurfer.sh"

}


I see that SetUpFreeSurfer.sh has this:


# Call configuration script:

source $FREESURFER_HOME/FreeSurferEnv.sh


After running module unload freesurfer several directories remain in $PATH:


echo $PATH
/path/to/freesurfer/fsfast/bin:/path/to/freesurfer/tktools:/path/to/freesurfer/mni/bin:/path/to/freesurfer/fsfast/bin:/path/to/freesurfer/tktools:/path/to/freesurfer/mni/bin


So $FREESURFER_HOME and $SUBJECTS_DIR are being unset but all of the other env vars are not. Is there a way to unset the vars from FreeSurferEnv.sh? A thread on SO mentions using unsetenv but perhaps there's an elseif that can be added to the modulefile?