zsh-users
 help / color / mirror / code / Atom feed
From: Philippe Troin <phil@fifi.org>
To: Florian Lindner <mailinglists@xgm.de>
Cc: zsh-users@zsh.org
Subject: Re: Correct way to set environment
Date: Sat, 15 Dec 2012 10:42:48 -0800	[thread overview]
Message-ID: <1355596968.28137.8.camel@air.home.fifi.org> (raw)
In-Reply-To: <CAJtBfr8JERUyiRuPYNDEhkiQBWRSJNxghy0r1o-BN7Q9QOgWtw@mail.gmail.com>

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.


  parent reply	other threads:[~2012-12-15 18:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-15 13:29 Florian Lindner
2012-12-15 13:44 ` Stefan Marx
2012-12-15 18:33 ` Peter Stephenson
2012-12-15 18:42 ` Philippe Troin [this message]
2012-12-15 19:19 ` Bart Schaefer
2012-12-15 19:34   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1355596968.28137.8.camel@air.home.fifi.org \
    --to=phil@fifi.org \
    --cc=mailinglists@xgm.de \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).