I wrote:
ersonally 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,
Rich Alderson wrote:
For this kind of thing, I revert to tcsh ...
Bash does have pattern matching in variable expansion. Changing the
suffix can be done by:
for f in *.foo; do mv $f ${f/%.foo/.bar}; done
Which is arguably simpler than my earlier example ...
I also sometimes have to rename files from mixed case or all caps to all
lower case, and bash has an expansion feature useful for that, too:
for f in *; do mv $f ${f,,}; done
',,' means convert all characters to lower case. '^^' would convert to
all upper case.
Thanks! I've read/skimmed the bash manual many times but somehow these
never took root in my brain.
--Toby
There's obviously a lot more that bash can do than what I've described.
For the fancier stuff I always wind up RingTFM.
Eric