Skip to content
Mark Lavi edited this page Jan 23, 2024 · 2 revisions

check_env is a test to check if environment variable(s) exist.

Choose from two methods:

  • Create or append to ~/.config/direnv/direnvrc a function with the contents below
  • Create ~/.config/direnv/lib/check_env.sh with the contents below
check_env() { local ret=0; for var in "$@"; do [[ -v $var ]] || { echo "$var is missing"; ret=1; }; done; return $ret; }

Usage

$ check_env HOME FOO BAR
FOO is missing
BAR is missing
$ echo $?
1