[Gllug] error in bash script to rename files in a directory

Steve Cobrin cobrin at highbury.net
Fri Dec 27 23:59:48 UTC 2002


On Friday 27 Dec 2002 22:34, Liam Delahunty wrote:
> Hi Chaps,
>
> I tried the following "script" in a shell...
>
> for i in `ls *.php3`; do mv $i `echo $i|tr 'php3' 'php'`; done
>

for file in *.php3
do
	mv $file `basename $file .php3`.php
done

> with the intention of renaming all the files in a folder from .php3
> to .php
>
> Instead, I now have *.phpp
>
> Could some kind soul explain what should I have done (and what
> fundamental concept I've got wrong...)

tr is not doing what you think it does, read the man page.

alternatively the following should work

for i in *.php3; do mv $i `echo $i | sed -e 's/\.php3$/.php/'`; done

>
> Kind regards,
> Liam Delahunty
> http://www.corx.co.uk | http://www.moderngent.com

-- Steve

ps. I hope we're not doing your homework too! :-)

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list