From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6579 invoked from network); 3 Sep 2004 17:22:20 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Sep 2004 17:22:20 -0000 Received: (qmail 1026 invoked from network); 3 Sep 2004 17:22:14 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Sep 2004 17:22:14 -0000 Received: (qmail 23776 invoked by alias); 3 Sep 2004 17:21:32 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7972 Received: (qmail 23762 invoked from network); 3 Sep 2004 17:21:32 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Sep 2004 17:21:32 -0000 Received: (qmail 99240 invoked from network); 3 Sep 2004 17:20:33 -0000 Received: from moonbase.zanshin.com (64.84.47.139) by a.mx.sunsite.dk with SMTP; 3 Sep 2004 17:20:30 -0000 Received: from toltec.zanshin.com (toltec.zanshin.com [64.84.47.166]) by moonbase.zanshin.com (8.13.1/8.13.1) with ESMTP id i83HKS7u007254 for ; Fri, 3 Sep 2004 10:20:29 -0700 Date: Fri, 3 Sep 2004 10:20:28 -0700 (PDT) From: Bart Schaefer Reply-To: zsh-users@sunsite.dk To: Zsh Users Subject: Re: Making a script 'sourceable' In-Reply-To: <20040903163509.GA12618@DervishD> Message-ID: References: <20040903163509.GA12618@DervishD> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Content-ID: 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 On Fri, 3 Sep 2004, DervishD wrote: > 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. > 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. Other options you might check: [[ -o SH_IN_STDIN ]] [[ -o MONITOR ]] > 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.