Bash Environment – How to Run a Program in a Clean Environment in Bash

bashenvironment-variables

I want to run a program in an empty environment (i.e. with no envariables set). How to do this in bash?

Best Answer

You can do this with env:

env -i your_command

Contrary to comments below, this does completely clear out the environment, but it does not prevent your_command setting new variables. In particular, running a shell will cause the /etc/profile to run, and the shell may have some built in settings also.

You can check this with:

env -i env

i.e. wipe the environment and then print it. The output will be blank.

Related Question