Quote $NVM_DIR in commands
Compare shell variable contents with a sentinel.
Collapsing some if/else conditions with elif
Use $() instead of backticks; add quotes
More shellcheck recommendations
Use _ instead of ~ as a sentinel
Adding some more quotes and $()