From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7877 invoked from network); 5 Sep 2005 20:08:51 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 5 Sep 2005 20:08:51 -0000 Received: (qmail 85853 invoked from network); 5 Sep 2005 20:08:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 Sep 2005 20:08:45 -0000 Received: (qmail 21197 invoked by alias); 5 Sep 2005 20:08:31 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9390 Received: (qmail 21187 invoked from network); 5 Sep 2005 20:08:30 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 5 Sep 2005 20:08:30 -0000 Received: (qmail 84356 invoked from network); 5 Sep 2005 20:08:30 -0000 Received: from vms048pub.verizon.net (206.46.252.48) by a.mx.sunsite.dk with SMTP; 5 Sep 2005 20:08:23 -0000 Received: from candle.brasslantern.com ([71.116.79.190]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IMD00HDO19WFZ51@vms048.mailsrvcs.net> for zsh-users@sunsite.dk; Mon, 05 Sep 2005 15:08:22 -0500 (CDT) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j85K8KuG008989 for ; Mon, 05 Sep 2005 13:08:20 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j85K8KfW008988 for zsh-users@sunsite.dk; Mon, 05 Sep 2005 13:08:20 -0700 Date: Mon, 05 Sep 2005 20:08:19 +0000 From: Bart Schaefer Subject: Re: Factoring out code In-reply-to: <20050905114253.GA7132@DervishD> To: Zsh Users Message-id: <1050905200819.ZM8987@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <20050905114253.GA7132@DervishD> Comments: In reply to DervishD "Factoring out code" (Sep 5, 1:42pm) X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 On Sep 5, 1:42pm, DervishD wrote: } } How can I make "common.sh" to run code BEFORE and AFTER some } point in the script which sources it Have you considered splitting common.sh into two files, the first called (for example) emulate.sh and the second common.sh, and then start the rest of your scripts with (again for example) . emulate.sh function help { ... } function doc { ... } . common.sh ?? This sort of thing is done quite frequently in languages like PHP that are used for writing web applications. You should probably also put all of these "include files" in a common subdirectory, so that you typically write . inc/emulate.sh function help { ... } function doc { ... } . inc/common.sh Another approach would be to have common.sh define a bunch of variables whose contents are snippets of shell code; e.g. . common.sh function help { ... } function doc { ... } eval ${_common_parse_argv:?'common.sh not sourced'} (See the manual for ${name:?message} semantics.) } if that code must modify global } variables in the caller and work like a cut'n'paste (I mean, for the } 'sourcer' script the code should run like if was cut from "common.sh" } and pasted into the file, just like a macro)? You have to be careful with this unless you're doing something like eval "$(