From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28268 invoked by alias); 29 Jul 2011 02:05:26 -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: 16154 Received: (qmail 17249 invoked from network); 29 Jul 2011 02:05:24 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.82.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:from:reply-to:to:date:in-reply-to:references:content-type :x-mailer:content-transfer-encoding:message-id:mime-version; bh=hJeACGqz2jL9oNodwRq2Kj7Cd+/m/QnDZHiYjsrme2Q=; b=Sv3svdS1e9XSFkwNHJjcuYzbRpJB4O6hmnF+krx+vH6r5W3ozgo5b0Aluudv7t9gPR yOnPSZPjK/ka6XJKNjTwD4V3zdsyLU92OMqiL5FCyP+69G+rGcWcwcou/k0Voy1CmbDS mSE84jio5fvq78cMjxo71u5DF0kaCM1W5JP00= Subject: Re: how to refer to basename of $0 From: Tomasz Moskal Reply-To: ramshackle.industries@gmail.com To: zsh-users@zsh.org Date: Fri, 29 Jul 2011 03:06:49 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.0.2 Content-Transfer-Encoding: 7bit Message-ID: <1311905211.7733.6.camel@localhost.localdomain> Mime-Version: 1.0 On Thu, 2011-07-28 at 21:39 -0400, TJ Luoma wrote: > Sorry folks, I'm explaining this really badly. Forget I said anything > about bash. I don't care about bash. I'm trying to leave bash behind. > > Let me start over. Here's what happens in zsh 4.3.11 > > # my comments are offset with # > # fyi - "Air%" is my prompt > > # just to show that $NAME is empty > Air% echo $NAME > Air% > > > # /tmp/.source has only one line: > Air% cat /tmp/.source > NAME=`basename $0` > > # here is my 'test.zsh' script: > Air% cat ./test.zsh > #!/bin/zsh > > . /tmp/.source > > echo "$NAME" > > exit 0 > > # So now I run 'test.zsh' : > > Air% ./test.zsh > .source > > # OK, so you can see that it output '.source' when I wanted it to > output 'test.zsh' > > # Next: rename /tmp/.source to ~/.zshenv > > Air% mv /tmp/.source ~/.zshenv > > # Edited 'test.zsh' is now this: > > Air% cat =test.zsh > #!/bin/zsh > > echo "$NAME" > > exit 0 > #EOF > > # now when I run 'test.zsh' again: > > Air% test.zsh > zsh > > # Someone suggested "unsetopt function_argzero" so I added that to .zshenv: > > Air% cat ~/.zshenv > unsetopt function_argzero > > NAME=`basename $0` > > # and re-ran test.zsh, which gave me: > > zsh > > > Is it even possible to set NAME in .zsh* (and have it return > 'test.zsh' or are they called too early in the process? > > TjL It's working here: % cat .zshenv unsetopt function_argzero name=`basename $0` % cat foo #!/bin/zsh . ~/.zshenv echo $name exit 0 % ./foo foo A bit perplexed, this is what I am... Have a look at this: % zsh -f % ./foo foo