When a conda environment is activated, conda remembers the previously activated environments. For example, if no environment is activated, calling conda activate foo and then conda deactivate results in no environment being active. However, calling conda activate foo, and then conda activate bar, and then conda deactivate results in the "foo" environment being active. Conda puts each environment on a stack as it is activated and deactivating merely pops one item off the stack.
How do I deactivate all conda environments when using the bash version of conda?
For example, if I had a script that rebuilt an environment, it would need to ensure that that environment is not currently active, so it should deactivate all environments. I could just stick ten or so conda deactivates at the top of the script and that would probably be enough, but I am looking for something less janky.