From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11378 invoked by alias); 9 Aug 2015 00:45:51 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20400 Received: (qmail 3546 invoked from network); 9 Aug 2015 00:45:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=KOOvsTXbC7JDKRO48dZjAnnvv6NZWJl7TM4zCHZhdpI=; b=e0q4ghfipB5KAr0CL2ebNP7V7TuvhmylSP6c0IhYzPxnXt4RnB+qih9FWCzr5mYoiV 12UtXOUDLNurtYa8e0p7IgTUbpM2QQEt98N/bz8612S+kbGUNO6cOIoo63BNkDcuYgSC a/VDjvskfUXtZTiVbdYLtehYhMHkg+AClD0HeQIijLwDb04iobX5ittGbaYZ6l9jvjvo VUsNpqYNh78QU/jIFljDFcEf2d7t0EabcZDtdOBolcQmWuv14rX4AkcD6Qlek+9xDOjB rFP71eGc6u6TY7iCX7VRASl+dg6rV9NhHCoJ4N+C5zUOelDfN6bTrjlrvOkhaD54+u1G AZ+A== MIME-Version: 1.0 X-Received: by 10.50.56.10 with SMTP id w10mr5180240igp.3.1439081146331; Sat, 08 Aug 2015 17:45:46 -0700 (PDT) In-Reply-To: <55C68669.8000408@netcologne.de> References: <55C68669.8000408@netcologne.de> Date: Sun, 9 Aug 2015 02:45:46 +0200 Message-ID: Subject: Re: Global And Local Variables in zsh Functions From: Mikael Magnusson To: Georg Wittig Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 On Sun, Aug 9, 2015 at 12:44 AM, Georg Wittig wrote: > Hi, > > I'm writing a zsh script that's constructing a rather complex rsync > command. One part of the script is constructing a list of exclude > commands for rsync. For this I use a global variable EXC. It is built > in the following way > > EXC='' > function my_f1 () { > EXC+=" --exclude='$1'"; > } > my_f1 /tmp > my_f1 /opt/windows7 > echo ">>>$EXC<<<" In addition to the other replies, you'll also want to change EXC to be an array, EXC=() my_f1() { EXC+=( --exclude=$1 ) } (note lack of quoting is intentional) Otherwise, you'll have a bad time trying to actually run the command. -- Mikael Magnusson