Re: Uppercasing filenames
On Sat 20 Sep 2003 23:35:34 +0000(+0200), Nicos Gollan wrote:
> Let's ignore the scripts intended purpose for a while and talk about what will
> happen when it's trying to process a filename with a space character...
>
> Quote all uses of variables:
>
> if [ -f "$file" ]
>
> Otherwise, if you have a file called 'long name', you would get the translated
> name 'LONG NAME' but the mv command would be expanded to
>
> mv long name LONG NAME
>
> This is NOT what you want.
>
> This seems to work (use mv instead of echoing the results):
>
> #!/bin/sh
>
> for i in $*; do
> if [ -f "$i" ]; then
> ucfile=`echo "$i"|tr [a-z] [A-Z]`
> if [ "$i" != "$ucfile" ]; then
> echo "$ucfile"
> fi
> fi
> done
To handle file names containing spaces, you also need to replace
for i in $*
with
for i in "$@"
or
for i
--
Cheers,
Clive
Reply to: