Question : Loop Syntax

I am pretty rusty with my loop syntax and was looking for a little help.

I am using mmv to rename .JPG extensions to .jpg  I would like to be able search a directory.  The problem is declaring the directory and using it correctly in the loop script.  The way I have it doesn't work...  I want to make sure that the directory is used for both mmv and convert commands.  Thank you.

#!/bin/sh
imagepath="/var/www/images/*"

for a in $imagepath;
do mmv \*.JPG \#1.jpg ;
do convert "$a" -resize 120x120 120x120/"$a";
done

Answer : Loop Syntax

Since you posted this in Perl zone, I'll give you a perl solution...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
#!/usr/local/bin/perl
use strict;
use warnings;
use File::Copy qw(mv);

my $imagepath = '/var/www/images';

opendir DIR, $imagepath or die "could not open $imagepath: $!";
while (my $file = readdir DIR) {
    next unless ($file =~ /\.JPG$/);
    my $nfile = $file;
    $nfile =~ s{\.JPG$}{.jpg};
    mv $file, $nfile or die "could not rename $file to $nfile: $!";
    system("convert \"$nfile\" -resize 120x120 120x120 \"$nfile\"") == 0 or warn "convert $nfile failed: $?";
}
closedir DIR;
Random Solutions  
 
programming4us programming4us