From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10556 invoked from network); 16 Jun 2000 21:45:02 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 16 Jun 2000 21:45:02 -0000 Received: (qmail 10452 invoked by alias); 16 Jun 2000 21:44:45 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3176 Received: (qmail 10445 invoked from network); 16 Jun 2000 21:44:43 -0000 From: "Bart Schaefer" Message-Id: <000616144430.ZM4632@candle.brasslantern.com> Date: Fri, 16 Jun 2000 14:44:30 -0700 In-Reply-To: <000616140019.ZM4608@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "Re: more fun with parameter expansion" (Jun 16, 2:00pm) References: <20000616145330.A8031@scowler.net> <000616140019.ZM4608@candle.brasslantern.com> X-Mailer: Z-Mail Lite (5.0.0 30July97) To: Clint Adams , zsh-users@sunsite.auc.dk Subject: Re: more fun with parameter expansion MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jun 16, 2:00pm, Bart Schaefer wrote: > Subject: Re: more fun with parameter expansion > > for f in **/*(DNon); do > mv -v $f ${${(M)f%/*}:+${${f%/*}:l:gs/ /_/}}${${${(M)f%/*}:-$f}:l:gs/ /_/} > done > > The `(on)' (order by name) is probably unnecessary, and won't work in 3.0.x > (though everything else should). Of course I completely forgot that the whole reason I split the thing into head and tail was because this needs to work in REVERSE name order. Sigh. The correct solution is for f in **/*(DNOn^M); do mv -v $i ${${(M)i%/*}:+${i%/*}}${${${(M)i%/*}:-$i}:l:gs/ /_/} done (note one fewer :l:gs and turn *off* markdirs) which *won't* work in 3.0.x because of no (On) glob flag. > Writing that one-liner out a bit longer might make this more readable: > > t=${(M)f%/*} # The tail of the path, including leading slash > h=${t:+${f%/*}} # The head of the path if the tail is non-empty > t=${t:-$f} # The tail is the path when the tail is empty > > h=$h:l # Downcase the head, same as ${(L)h} > h=$h:gs/ /_/ This was my error; don't modify the head, instead wait for it to become the tail (that's why the reverse ordering) and then modify it. > t=$t:l # Downcase the tail > t=$h:gs/ /_/ And I forgot that braces are needed because of the space: t=${t:gs/ /_/} > mv $f $h$t > > The last five steps could be written as > > mv $f ${${:-$h$t}:l:gs/ /_/} Rather: mv $f $h${t:l:gs/ /_/} which isn't nearly as mysterious. Oh well.