From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18217 invoked by alias); 15 Dec 2012 18:33:49 -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: 17475 Received: (qmail 14018 invoked from network); 15 Dec 2012 18:33:47 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 74.125.82.171 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-proxyuser-ip:date:from:to:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=QCL37M77MJVRe7l6frtbQ+7bmJbyob53TXNFPuofp4M=; b=gp/z7IKrTMzUvUd97yMhzlOZAwpGxXIBN9v37bOicw50V2hUBMP87tYPYtNq3Q5e7F OZVflBuZk1JFjF8Mkw1sNEKhtaz+ej8NfhwvejP/rhnumDeR5mAYelHVbvgXERMcd96L qNR11qhjz6bzpXv8UjpHPf65vW522Ouonl4Z3R+j+kwNfmdNtPoTmnPUqCMgrjplgfS9 DdOk7BTfbGo1RcVs200SiILJ4nKtMhoRI2CBYkgqahF9x+EuwBDUIHXuWAaOLcEYwu1p +bduoS4zXvfWZJ51rNTxXbdCGEZ3TXEfAy+tD4mU2t/xMKLXyqk+gU0p21BXoBsEnex3 mW1g== X-ProxyUser-IP: 82.8.55.192 Date: Sat, 15 Dec 2012 18:33:39 +0000 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: Correct way to set environment Message-ID: <20121215183339.5e22fc1c@pws-pc.ntlworld.com> In-Reply-To: References: X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQkIQXLphrT5Hi9nUPurm6YfjcCQ/w3+PzdOF5nny+j0Tp+coTpmdMfpquX+cep374FKAyKO On Sat, 15 Dec 2012 14:29:24 +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. > > What is the best way to set some environment variables, no matter how > (login, interactive, ...) the shell is invoced? There are various things here: (i) you need to ensure variables get exported, as Stefan pointed out, so use the "export" keyword. You don't need to do this every time you set the variable, only once within each shell; (ii) you need to put them in a file that gets sourced for all shells (except when you give the "-f" option when starting the shell): .zshenv is fine, as long as you understand the effect, though for some reason this occasionally inspires holy wars (I think on the basis that sometimes people don't understand the effect); (iii) you don't want the paths to keep getting extended with repeated values: for this, zsh has the -U (unique) keyword. It only works on colon-separated arrays if the shell knows that's what they are. To do that, you can associate the array with ("tie" it to) a real array --- you can still set the colon-separated array, however, so if you want you can ignore the real array completely. This is already done for you for PATH and path, because they're special, but you need to do it explicitly for PYTHONPATH and pythonpath. (PATH is probably already exported but it doesn't have the -U flag by default; I've used the "export" keyword anyway to express the intention.) So put the following in .zshenv: export -U PATH=$HOME/flof/src:$HOME/software/bin:$PATH PATH=/home/florian/software/src/boar:$PATH export -TU PYTHONPATH=$HOME/flof/src:$PYTHONPATH pythonpath -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/