22

As I know, newly running shell script inherits it's environment variables. Is there a way to block this? (running shell without variable inheriting)

Eonil
  • 11,009

2 Answers2

28

It seems you can prefix your script with env -i which will clear the environment before running the script:

env -i sh test.sh

From man env:

-i, --ignore-environment
              start with an empty environment

Not sure why you would want to do this though...

vmfarms
  • 3,207
3

One possibility (although it looks rather ugly):

exec -c $SCRIPT will start $SCRIPT with an empty environment. (see man bash search for exec \[-cl\]).

weeheavy
  • 4,149
  • 1
  • 30
  • 41