asdf-vm / asdf-elixir

Elixir plugin for asdf version manager
https://github.com/asdf-vm/asdf
MIT License
473 stars 70 forks source link

Avoid unbound variable error when nounset is enabled #125

Closed robsonpeixoto closed 1 year ago

robsonpeixoto commented 1 year ago

If you are using asdf-direnv with asdf-elixir and try to execute the command asdf direnv shell elixir $version -- echo "hi" will raise the error "unbound variable" because the direnv uses set -u by default.

I got this error when I tried to setup this hook on ~/.asdfrc to always install the local.hex and local.rebar:

post_asdf_install_elixir = asdf direnv shell elixir $version -- mix do local.hex --force, local.rebar --force

The hack is: always use an empty string when the variable is not defined.

Besides, it is possible to add a set +u at the beginning of the file and set -u at the end, but set set -u at the end can cause an unexpected side effect for another script.

Stratus3D commented 1 year ago

Thanks @robsonpeixoto ! I think this is the right solution.