Re: Uppercasing filenames
On Sat 20 Sep 2003 17:06:26 +0000(-0400), Jeff Elkins wrote:
> I need to convert a bunch of filenames to uppercase. I tried the script below,
> which does...nothing.
>
> #!/bin/sh
> for file in $*
> do
> if [ -f $file ]
> then
> ucfile=`echo $file | tr [a-z] [A-Z]`
> if [ $file != $ucfile ]
> then
> mv -i $file $ucfile
> fi
> fi
> done
>
> Any tips?
If there are any files in the current directory whose names consist of a
single letter, then one or both of [a-z] and [A-Z] (depending on LC_COLLATE)
will be expanded by the shell and the tr command will not receive the
arguments you intended. Try quoting the arguments like this:
tr '[a-z]' '[A-Z]'
--
Cheers,
Clive
Reply to: