From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17602 invoked from network); 11 Oct 2002 09:03:30 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 11 Oct 2002 09:03:30 -0000 Received: (qmail 10568 invoked by alias); 11 Oct 2002 09:03:12 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 17811 Received: (qmail 10554 invoked from network); 11 Oct 2002 09:03:09 -0000 X-VirusChecked: Checked In-reply-to: <20021010194154.GA10963@DervishD> From: Oliver Kiddle References: <20021010194154.GA10963@DervishD> To: DervishD cc: zsh-workers@sunsite.dk Subject: Re: Recursion and shell functions MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14765.1034326857.1@logica.com> Date: Fri, 11 Oct 2002 10:02:37 +0100 Sender: kiddleo@logica.com Message-Id: On 10 Oct, you wrote: > First of all, please excuse this a-bit-off-topic question, but I > need to know if a feature available in zsh is portable. > > I need to do recursion in a directory tree and have two options; > first one is doing a 'for' loop recursively calling the shell > function which performs the actions: > setting the permissions. This may seems unreasonable (two > recursions...) but it's necessary since the recursive function call > overwrites local variables, and I *cannot* set them as local, since > 'local' is not a portable keyword :((( I need If you know that you will at least have ksh88, you can get local variables by using the function name { ... } syntax for functions and using typeset to declare variables. The bourne shell doesn't have local variables except for the positional parameters and you can use them. I think this will be portable: func() { set * while [ "$1" ]; do if [ -d "$1" ]; then cd $1 func cd .. fi shift done } Something like find is going to be more reliable though. Oliver This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.