Bash – how to prevent exported environment variables to be recognized/accessible by a child shell (bash)

bashenvironment-variables

So, I need to prevent loads of exported variables to be recognized by a child shell.

The problem is an application (Wine+UDK) won't build projects with too many (>65535) bytes on the environment, and mine has a lot (95323) after I use a project (ScriptEchoColor) that shares environment variables between any bash shells.

I can't find a command that will allow me to spawn a child shell that won't accept current environment variables and instead will just use the ones that are set on my user profile and on the system as a whole.

I tried many options shown at bash --help.

Best Answer

You can use the env command to start a process with a clean environment. Here is an example:

env -i /bin/myprog

If you still need to export some variables, you can do so in the call:

env -i MYVAR=foo /bin/myprog

The env command is required by POSIX.