On 12/16/11 3:51 PM, Eric Smith wrote:
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:
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.
This uppercase/lowercase feature is specific to bash v4.x...
Not Directed At Eric:
This is one of my big gripes about shell-scripting. It seems that a
lot of people write scripts with the intent of distribution, but also
with built-in assumptions that the target user and system will be
version- and filesystem-identical to the development environment.
ASSuming that "#!/bin/sh" will execute bash is a very common example.
Doing flaoting-point math in ksh is another - to this day most systems
execute ksh88 by default.
Granted you can't provide for every possible target environment, but
a little error checking and problem reporting, along with a lot of
commenting, sure goes a long way.
Doc