bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How not to inherit any environment variable from parent process?


From: Bob Proulx
Subject: Re: How not to inherit any environment variable from parent process?
Date: Tue, 22 Jun 2010 22:42:19 -0600
User-agent: Mutt/1.5.18 (2008-05-17)

Peng Yu wrote:
> I use bash --noprofile to start a bash session. Since this doesn't
> source any profile files, I'd think that no environment variable
> should be set. But I still see environment variables set. Are they
> inherit from the parent session. Is there a way to start a bash
> session without using parent environment variables?

Use the 'env' command with the -i option to start with an empty
environment.

  $ env | wc -l
  40

  $ env -i env | wc -l
  0

But you will almost always want some environment variables.  Pass the
ones you want on the command line.

  $ env -i HOME=$HOME PATH=$PATH env | wc -l
  2

Here I am confusingly using 'env' both to invoke a command and to be
the command invoked but it was the most convenient command to use.
When invoked with no arguments 'env' prints the environment.

  $ env -i HOME=$HOME PATH=$PATH somecommand someargs

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]