From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24965 invoked from network); 12 Jun 1998 08:20:13 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 12 Jun 1998 08:20:13 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id EAA19498; Fri, 12 Jun 1998 04:15:53 -0400 (EDT) Resent-Date: Fri, 12 Jun 1998 04:15:32 -0400 (EDT) Message-Id: <199806120816.EAA22173@luomat.peak.org> Content-Type: text/plain MIME-Version: 1.0 From: Timothy J Luoma Date: Fri, 12 Jun 98 04:15:57 -0400 To: zsh-users@math.gatech.edu Subject: help with 'rename' function Resent-Message-ID: <"7gur51.0.2m4.OEEWr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1592 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu I used to have a binary that did this, but I've lost it. What it did was simple: it changed extensions of filenames. 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 and it would go on its way... or if it was just one file: rename foo.THIS THIS=THAT I've tried to make a function which does this, but it fails: (the $others variable is ALL the file names rather than cycling through one by one) rename () { local i last oldext newext short new others last=`echo $* | awk '{print $NF}'` # all the args except the last one others=`echo $* | sed "s/ $last$//g"` oldext=`echo $rename | tr -s '=' ' ' | awk '{print $1}'` newext=`echo $rename | tr -s '=' ' ' | awk '{print $2}'` echo "oldext is $oldext" echo "newext is $newext" for i in $others do short=`echo $i .$oldext` new=`echo $short.$newext` mv $i $new done }