From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11335 invoked from network); 29 Sep 2005 03:03:35 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 29 Sep 2005 03:03:35 -0000 Received: (qmail 35940 invoked from network); 29 Sep 2005 03:03:28 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 29 Sep 2005 03:03:28 -0000 Received: (qmail 7868 invoked by alias); 29 Sep 2005 03:03:19 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9458 Received: (qmail 7859 invoked from network); 29 Sep 2005 03:03:18 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 29 Sep 2005 03:03:18 -0000 Received: (qmail 34883 invoked from network); 29 Sep 2005 03:03:18 -0000 Received: from vms044pub.verizon.net (206.46.252.44) by a.mx.sunsite.dk with SMTP; 29 Sep 2005 03:03:18 -0000 Received: from candle.brasslantern.com ([71.116.81.225]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0INK008R45TFTF54@vms044.mailsrvcs.net> for zsh-users@sunsite.dk; Wed, 28 Sep 2005 22:03:16 -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 j8T33E3T025024 for ; Wed, 28 Sep 2005 20:03:14 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j8T33DhL025023 for zsh-users@sunsite.dk; Wed, 28 Sep 2005 20:03:13 -0700 Date: Thu, 29 Sep 2005 03:03:13 +0000 From: Bart Schaefer Subject: Re: add-path, rm-path In-reply-to: <7c737f3005092815162ea22b0c@mail.gmail.com> To: zsh-users@sunsite.dk Message-id: <1050929030313.ZM25022@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <7c737f3005092815162ea22b0c@mail.gmail.com> Comments: In reply to Deliverable Mail "add-path, rm-path" (Sep 28, 3:16pm) 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 28, 3:16pm, Deliverable Mail wrote: } } Many people have python-esque scripts which add a path to a PATH-like } variable only if it's not there already, or remove it from there completely. } I wonder whether zsh has it embedded? Zsh has three components that together accomplish this. The first is automatic linkage between arrays and colon-separated scalars, in this case the array "path" and the scalar "PATH". The second is "typeset -U" for creating self-uniquifying arrays. The third is ${array:#pattern} for removing elements matching a pattern from an array. The only time you need a function is when you want to control the order in which the single remaining instance of a duplicated element appears in the array, after de-duping. The "typeset -U" behavior is to keep the one with the lowest array index, even if that means inserting a new element and deleting an existing equivalent one.