From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25513 invoked from network); 12 Jun 1998 09:13:17 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 12 Jun 1998 09:13:17 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id FAA20352; Fri, 12 Jun 1998 05:08:40 -0400 (EDT) Resent-Date: Fri, 12 Jun 1998 05:08:22 -0400 (EDT) Message-Id: <199806120909.LAA21384@hydra.ifh.de> X-Authentication-Warning: hydra.ifh.de: pws owned process doing -bs To: Timothy J Luoma , zsh-users@math.gatech.edu (Zsh users list) Subject: Re: help with 'rename' function In-reply-to: "Timothy J Luoma"'s message of "Fri, 12 Jun 1998 04:15:57 MST." <199806120816.EAA22173@luomat.peak.org> Date: Fri, 12 Jun 1998 11:09:12 +0200 From: Peter Stephenson Resent-Message-ID: <"DgIJr1.0.Oz4.40FWr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1593 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: > I used to have a binary that did this, but I've lost it. > > What it did was simple: it changed extensions of filenames. It's perennially annoying UNIX doesn't have this. On the other hand, if it did it would probably be so inscrutable as to be almost useless. If you want a proper programme, search the archives for mmv. There's also a widely distributed perl script called rename which allows perl operations on the file name, e.g. 's/\.this$/.that/' in this case. (I can mail my version.) If you want a shell function, it's appended... > For example, say you have a bunch of files which ended with .THIS and you > wanted to change them to end with .THAT > > You would do > > rename *.THIS THIS=THAT ...the difference is it was easier to stick the THIS=THAT argument first rather than last. Everything's done by the shell, so it's a bit simpler. It's limited to suffixes as written. Note the -f if you want to overwrite an existing file. # rename.zsh local force [[ $1 = -f ]] && shift && force=1 if [[ $# -lt 2 || $1 != *=* ]]; then print "Usage: $0 oldsuf=newsuf file ..." 2>&1 fi local old new ofile nfile old=${1%=*} new=${1#*=} shift for ofile in $*; do nfile=${ofile%$old}$new if [[ -f $nfile && $force != 1 ]]; then print "$nfile already exists" 2>&1 else mv $ofile $nfile fi done # end -- Peter Stephenson Tel: +39 50 844536 WWW: http://www.ifh.de/~pws/ Gruppo Teorico, Dipartimento di Fisica Piazza Torricelli 2, 56100 Pisa, Italy