Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

help with 'rename' function



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

}
		



Messages sorted by: Reverse Date, Date, Thread, Author