[Gllug] error in bash script to rename files in a directory
Paul Cupis
paul at cupis.co.uk
Fri Dec 27 23:09:10 UTC 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
>
> 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...)
I would have done something like:
rename 's/php3$/php/;' *.php3
or:
for file in `ls *.php3`; do mv $file `basename $file php3`.php; done
I've just tested both of these, so assuming I copied them into this email
okay, they should work. (Okay, I tested them on .html -> .htm (with rename)
and back again (with for file). Sue me.)
In short, I think you must have some error with your echo/tr section.
Regards,
Paul Cupis
- --
paul at cupis.co.uk
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)
iD8DBQE+DN2rIzuKV+SHX/kRArQbAJ4uFTyLFvr6++Pnbw8A5rp60B5M9gCdHFJE
I1yvLrgicPW4+zZLGiV6iJo=
=xLM+
-----END PGP SIGNATURE-----
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list