unset bash variable not working as expected
Author: trodemasterCreated Aug 22, 2024Updated Aug 10, 2026
LabelsBug
Describe the bug
I thought you could include unset commands in a direnv config and it would clear variables if they exist. https://direnv.net/man/direnv.1.html#usage I'm seeing errors that stop direnv from continuing when I put an unset line in a .env config file. The export lines will work as expected if I don't include the unset ones.
To Reproduce
$ mkdir ~/scratch/direnvtest
$ echo 'unset FOO'>~/scratch/direnvtest/.env
$ cd ~/scratch/direnvtest
direnv: error /Users/blake/scratch/direnvtest/.env is blocked. Run `direnv allow` to approve its content
$ direnv allow
direnv: error invalid line: unset FOO
direnv: export ~XPC_SERVICE_NAMEExpected behavior
When a line of unset FOO exist in the .env file direnv will unset the variable if it exists. In my test case FOO does not exist.
Environment
- OS: macOS 14.6.1 23G93 arm64
- Shell: GNU bash, version 5.2.26(1)-release (aarch64-apple-darwin23.2.0)
- Direnv version 2.34.0 & 2.33.0
Additional context Hopefully, I'm not missing something basic here...
Source: direnv/direnv