spoovy
spoovy

Reputation: 343

'env -i' -- doesn't remove all env vars from subshell

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

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

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

Related Questions