Reputation: 343
I thought that env -i
runs a command with a blank environment, but the following code (in a bash v4.4 function) works -- as in, COMMAND is executed with only env vars from ENVFILE.
So, why are the explicitly-set env vars ENVFILE and COMMAND not removed by env -i
?
export local ENVFILE="$1" COMMAND="$2"
/usr/bin/env -i /bin/bash -c ". ${ENVFILE}; ${COMMAND}"
Upvotes: 2
Views: 363
Reputation: 799200
Because they're substituted in the current shell, not the invoked one.
export local ENVFILE="$1" COMMAND="$2"
/usr/bin/env -i /bin/bash -c '. ${ENVFILE}; ${COMMAND}'
Upvotes: 3