From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28513 invoked from network); 4 Sep 2004 11:06:25 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 4 Sep 2004 11:06:25 -0000 Received: (qmail 15817 invoked from network); 4 Sep 2004 11:06:19 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 Sep 2004 11:06:19 -0000 Received: (qmail 26498 invoked by alias); 4 Sep 2004 11:06:11 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7974 Received: (qmail 26482 invoked from network); 4 Sep 2004 11:06:11 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 4 Sep 2004 11:06:11 -0000 Received: (qmail 14762 invoked from network); 4 Sep 2004 11:06:11 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 4 Sep 2004 11:06:09 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id i84B67100771 for ; Sat, 4 Sep 2004 13:06:07 +0200 Received: from disposable1@telefonica.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1C3YOC-0003Lh-00>; Sat, 4 Sep 2004 13:07:24 +0200 Date: Sat, 4 Sep 2004 13:07:24 +0200 From: DervishD To: Zsh Users Subject: Re: Making a script 'sourceable' Message-ID: <20040904110724.GA12874@DervishD> Mail-Followup-To: Zsh Users Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Organization: Pleyades X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-0.0 required=6.0 tests=BAYES_44 autolearn=no version=2.63 X-Spam-Hits: -0.0 Hi Bart :) * Bart Schaefer dixit: > > That given, I'm trying to do two things. First one is detecting > > the 'sourcing' non portably, in zsh. > It can be done if setopt NO_FUNCTION_ARG_ZERO is in effect before the > script is sourced by comparing $0 either to $SHELL or to the name of > the script. Oh, I forgot FUNCTION_ARGZERO. For scripts not intended to be 'exported' outside my system this will do, thanks a lot :) > > thinking about now is to check the value of the option 'interactive'. > > If it is on, chances are that we have sourced the script. Otherwise, > > we may not. This is not perfect, though, because you can run a script > > (interactive=off) and then source the other script within... > If all your scripts check both the option and the state of $0 and then > explicitly turn off FUNCTION_ARG_ZERO, you're pretty much guaranteed to > catch direct sourcing the with the options and indirect sourcing with $0. I'll give it a try. > > The second thing is derived from the above question: since > > checking for 'sourcery' ;) is very difficult even non portably, I've > > thought about making my zsh scripts sourceables. > Lloyd Z. has the way of it. Well, an extra fork... I don't really like that method, but... I was thinking about writing the scripts carefully so they don't mess with the current environment. The main problem seems to be the environment variables and, in the case of zsh, the options (a portable shell script won't mess with the options). But Lloyd's solution is more reliable and the price, in modern OS's, is almost negligible. Thanks for your help. -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/