From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27801 invoked by alias); 11 Feb 2011 03:30:03 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28735 Received: (qmail 7541 invoked from network); 11 Feb 2011 03:29:52 -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,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110210192945.ZM31349@torch.brasslantern.com> Date: Thu, 10 Feb 2011 19:29:45 -0800 In-reply-to: Comments: In reply to Greg Klanderman "Re: loading user startup files for zsh scripts" (Feb 10, 8:42pm) References: <19792.22365.139876.599478@gargle.gargle.HOWL> <110207213357.ZM22407@torch.brasslantern.com> <20110208172056.6a985c90@pwslap01u.europe.root.pri> <110208205856.ZM24066@torch.brasslantern.com> <110209085358.ZM29014@torch.brasslantern.com> <110210095253.ZM30860@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: loading user startup files for zsh scripts MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 10, 8:42pm, Greg Klanderman wrote: } } > source /the/shared/zshenv $0 } } Hmmm, AFAICT, when loading .zshenv, $0 is /bin/zsh even for shell } scripts. It does contain the script path once in the script. Well, that certainly takes me by surprise, because I was sure I'd tried that ... but indeed looking through init.c the script name of $0 isn't set up until after ALL the init files have been read. This is odd considering that $* has already been set to the script arguments by the time .zshenv is processed. It also means that zsh will read all the init files before discovering that it can't read the script file. I'm also finding it a little weird that $0 apparently might be a metafied string, since setupshin() believes that unmeta(runscript) is necessary before calling e.g. access(). As far as I can tell the value would never be unmetafied before being returned via $0, so that would imply there are circumstances in which $0 is broken. I don't know what they'd be. Earlier: } On a related note, would you be opposed to adding some way to find out } definitively whether you're running as a script from within zsh? } Would adding a new parameter be best? Can you suggest a name? Is } runscript != NULL in zsh_main() the right condition to use? Or maybe } just set some parameter to the value of runscript when set? I'm inclined to suggest ZSH_SCRIPT to be initialized from runscript. I'd also like to get ZSH_INTERPRETER to be the actual path to the shell executable, but I suspect that's not universally available from the OS. Returning to your original problem ... I don't suppose all these user's hosts are running linux? You can examine /proc/$$/cmdline to find out if a script name appears.