How to give your program a blank ENV

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-11-23

The code on your development machine often is dependent on ENV from the parent process - e.g. PATH, USER, and other variables. These assumptions, when implicit, can lead to surprises when later deploying.

The following code allows you to remove all inherited ENV variables from parent process and give you a clean slate:

env_hash = {}
system(env_hash, "./frob", unsetenv_others: true)

Resources