From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25661 invoked from network); 12 Jun 1998 09:31:35 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 12 Jun 1998 09:31:35 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id FAA21317; Fri, 12 Jun 1998 05:25:30 -0400 (EDT) Resent-Date: Fri, 12 Jun 1998 05:25:17 -0400 (EDT) From: Zefram Message-Id: <199806120926.KAA09704@taos.demon.co.uk> Subject: Re: help with 'rename' function To: luomat+Lists/Zsh/users@luomat.peak.org (Timothy J Luoma) Date: Fri, 12 Jun 1998 10:26:15 +0100 (BST) Cc: zsh-users@math.gatech.edu In-Reply-To: <199806120816.EAA22173@luomat.peak.org> from "Timothy J Luoma" at Jun 12, 98 04:15:57 am X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"u9ZR51.0.SC5.xFFWr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1595 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Timothy J Luoma wrote: >You would do > > rename *.THIS THIS=THAT function rename { emulate zsh setopt localoptions integer st=0 local pat old new f if (( $# < 2 )) || { pat=$argv[$#]; [[ $pat != *\=* ]]; }; then echo >&2 "Usage: rename =" return 2 fi old=${pat%%\=*} new=${pat#*\=} for f in $argv[1,-2]; do if [[ $f != *$old ]]; then st=1 echo >&2 "$f: does not end with suffix \`$old'" elif ! mv $f ${f%$old}$new; then st=1 fi done return $st } If you use the files module, then this function does not use any external commands. -zefram