Josh Dersch wrote:
Wow, that's so elegant. It only requires spawning
two
processes, piping to a general purpose programming
language, and using regexps to make it work!
Bear in mind that a big part of the Unix philosophy is that rather than
providing tools that directly do anything you might need, Unix (and
associated software) are intended to give you simple tools that you can
combine, such that you can easily get more expressive power than can be
provided by a single complex tool. That includes considering the shell
as one of the tools. It isn't intended that the shell alone do
everything you might want; it is fully expected that you will have tasks
that require piping commands together.
Whether that philosophy is appropriate for the average user, and whether
Unix and related software actually adhere to that philosophy any more
are debatable points. Whether the shell should have any easy way to
rename all the files *.foo to *.bar is an interesting question. The
fact that it is easy to do on DEC-like command parsers doesn't imply
that it's such a common operation that the shell should offer it. I
would actually argue the opposite; since Unix shells have been around
for many years without anyone being convinced that that capability is
necessary, it is clear that it is not a common operation for most
people, and that it's OK to have to combine a few tools to do it.
However, I'll have to agree with you that the given solution is
inelegant. I would say that anything that involves the use of Perl is
by definition inelegant. That's spoken by someone who has once written
a non-trivial piece of software in Perl, and lived to regret it.
Personally I use a shell for loop with mv and basename, like:
for f in *.foo; do mv $f `basename $f .foo`.bar; done
That won't work when you want to change something other than the suffix
of a file, so knowledge of other Unix tools is helpful. For more
complex mass renamings, which I do even less frequently, I do tend to
use sed for filename manipulation. It's more powerful, but not as easy
to use. On the other hand, it's less powerful than Perl. I don't view
that as a disadvantage. I don't want a ten pound sledge when I need to
drive a finishing nail.
Eric