From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3322 invoked by alias); 15 Dec 2012 18:50:55 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17476 Received: (qmail 9831 invoked from network); 15 Dec 2012 18:50:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at fifi.org designates 173.255.216.206 as permitted sender) Message-ID: <1355596968.28137.8.camel@air.home.fifi.org> Subject: Re: Correct way to set environment From: Philippe Troin To: Florian Lindner Cc: zsh-users@zsh.org Date: Sat, 15 Dec 2012 10:42:48 -0800 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.4.3 (3.4.3-1.fc17) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit On Sat, 2012-12-15 at 14:29 +0100, Florian Lindner wrote: > I'm a bit puzzled about the way to set global environment variables. > > I've ushed .zshenv for that purpose since it is sourced on every shell > invocation. > > florian@horus ~ % cat .zshenv > PATH=$HOME/flof/src:$HOME/software/bin:$PATH > PATH=/home/florian/software/src/boar:$PATH > > PYTHONPATH=$HOME/flof/src:$PYTHONPATH > > > No other relevant z-files are present. This works as far as it sets > the PYTHONPATH variable but if I launch python it is not taken into > account. When I use export PYTHONPATH, the pythonpath gets longer and > longer if I invoke a zsh session within a zsh session. First thing: unless the variable is exported, it remains as a shell variable and does not get into the environment. You do need to export the variable. When you do this, as you have noticed, because .zshenv is sourced at every subshell invocation, the path keeps growing because you keep appending or prepending values to the path every time. > What is the best way to set some environment variables, no matter how > (login, interactive, ...) the shell is invoced? You could use a guard environment variable: if [[ $MY_ENVIRONMENT != yes ]] then export PATH=$HOME/flof/src:$HOME/software/bin:$PATH export PATH=/home/florian/software/src/boar:$PATH export PYTHONPATH=$HOME/flof/src:$PYTHONPATH export MY_ENVIRONMENT=yes fi Or you could only append a path to these variables if they don't contain it already. Phil.