From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10260 invoked by alias); 29 Jul 2011 14:09:31 -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: 16160 Received: (qmail 16200 invoked from network); 29 Jul 2011 14:09:30 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at benizi.com does not designate permitted sender hosts) Date: Fri, 29 Jul 2011 10:08:58 -0400 (EDT) From: "Benjamin R. Haskell" To: Tomasz Moskal cc: zsh-users@zsh.org Subject: Re: how to refer to basename of $0 In-Reply-To: <1311940087.1494.27.camel@localhost.localdomain> Message-ID: References: <110728210438.ZM24370@torch.brasslantern.com> <1311940087.1494.27.camel@localhost.localdomain> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII On Fri, 29 Jul 2011, Tomasz Moskal wrote: > On Thu, 2011-07-28 at 21:04 -0700, Bart Schaefer wrote: >> On Jul 28, 9:39pm, TJ Luoma wrote: >> } >> } Is it even possible to set NAME in .zsh* (and have it return >> } 'test.zsh' or are they called too early in the process? >> >> This is sounding awfully familiar. Oh, it was on zsh-workers, where >> some of the -users crowd would not have seen it. >> >> Starts here: >> >> http://www.zsh.org/mla/workers/2011/msg00159.html >> >> Interesting branch begins here: >> >> http://www.zsh.org/mla/workers/2011/msg00163.html >> >> Particularly: >> >> http://www.zsh.org/mla/workers//2011/msg00172.html > > Thanks for the links, but I am still baffled - basename $0 is > working here without any problems: > > % cat ~/.zshenv > unsetopt function_argzero > name=`basename $0` > > % cat ./foo > #!/bin/zsh > . ~/.zshenv > echo $name > exit 0 The point wasn't quite the same (didn't involve "source"-ing .zshenv). $0 doesn't work if used inside startup files (.zshenv/.zshrc/.zprofile). When you source it manually, it's not treated specially. Just wanted to note that the '%x' that I pointed out does work, though: ## as the first line of .zshenv (so, will be run when starting zsh) $ sed 1q ~/.zshenv echo in .zshenv 0=$0 %x=${(%):-%x} ## results in: $ zsh in .zshenv 0=zsh %x=/home/bhaskell/.zshenv -- Best, Ben