From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9146 invoked from network); 26 May 2004 09:23:45 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.86) by ns1.primenet.com.au with SMTP; 26 May 2004 09:23:45 -0000 Received: (qmail 17540 invoked from network); 26 May 2004 09:23:03 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 May 2004 09:23:03 -0000 Received: (qmail 5306 invoked by alias); 26 May 2004 09:22:50 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7479 Received: (qmail 5289 invoked from network); 26 May 2004 09:22:49 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.86) by sunsite.dk with SMTP; 26 May 2004 09:22:46 -0000 Received: (qmail 16755 invoked from network); 26 May 2004 09:22:46 -0000 Received: from lhuumrelay3.lnd.ops.eu.uu.net (62.189.58.19) by a.mx.sunsite.dk with SMTP; 26 May 2004 09:22:44 -0000 Received: from MAILSWEEPER01.csr.com (mailhost1.csr.com [62.189.183.235]) by lhuumrelay3.lnd.ops.eu.uu.net (8.11.0/8.11.0) with ESMTP id i4Q9MHv13898 for ; Wed, 26 May 2004 09:22:17 GMT Received: from EXCHANGE02.csr.com (unverified [192.168.137.45]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Wed, 26 May 2004 10:21:44 +0100 Received: from news01.csr.com ([192.168.143.38]) by EXCHANGE02.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 26 May 2004 10:24:32 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (Postfix) with ESMTP id B15A36E0205 for ; Wed, 26 May 2004 10:22:15 +0100 (BST) Received: from csr.com (pws@localhost) by news01.csr.com (8.12.10/8.12.10/Submit) with ESMTP id i4Q9MFOJ013293 for ; Wed, 26 May 2004 10:22:15 +0100 Message-Id: <200405260922.i4Q9MFOJ013293@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-users@sunsite.dk Subject: Re: Problems with for loops and : modifiers In-reply-to: "pleb@iridescent.org"'s message of "Wed, 26 May 2004 01:55:52 PDT." Date: Wed, 26 May 2004 10:22:15 +0100 From: Peter Stephenson X-OriginalArrivalTime: 26 May 2004 09:24:32.0249 (UTC) FILETIME=[40B08690:01C44303] 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_50 autolearn=no version=2.63 X-Spam-Hits: 0.0 pleb@iridescent.org wrote: > I'm having problems doing something that should be simple. I want to iterate > over a set of files in a directory and run some commands on those files. In t > he command I would like to strip the suffix of a filename away (ie basename) > and add a new suffix. > > I can do this interactively in zsh, using several of the different builtin "f > or" commands, but not in the following shell script. > > Q: > > 1. Why do the "for" loops work interactively and get a syntax error in a scri > pt? To me a newline terminator is a newline terminator. > > 2. Maybe I have the sense of SHORT_LOOPS backward? > > 3. Why does the :r modifier work interactively and not in a script? > > 4. What are the suggested ways to do what I want to do? It's possible you have different options set in .zshrc or /etc/zshrc. Those won't be used in a script, only .zshenv or /etc/zshenv. (I tend to prefer to write scripts beginning `emulate zsh', which put the shell into a known mode, and set any necessary options explicitly.) > echo "two" > #file get echoed, but :r is broken > for i in *.h > do > echo ${i}:r > done Change the substitution to ${i:r}. The ${...} insulates the parameter substitution from other stuff around, so :r is not active. You say $i:r is broken in the other example: the only thing I can find that turns off modifiers is the ksh_arrays option. Try adding `setopt no_ksh_arrays' at the start of the script. If that works, something in /etc/zshenv or ~/.zshenv is setting it. I'd recommend sticking with the form of `for' shown above in a script, since it's standard and unambiguous. -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************