Brad Lucas

Programming, Clojure and other interests
July 22, 2017

Bash With An Empty Environment

When writing bash scripts that look for environment variables it is a good idea to check that these environment variables exist at the top of the script. For this you do things like the following.

if [[ -z $LOG ]]; then
  echo "Missing LOG environment variable"

Now once you've created your environment variable how can you test your script for the case where the environment variable doesn't exist? For this you can open another bash shell with no environment variables. An empty environment if you will. To do this try the following.

$ env -i bash --norc --noprofile

With this you can test your script and make sure it exits when the required environment variables don't exist.

Tags: bash