I want to rotate all the images in a directory that match a pattern.
So far I have:
for file in `ls /tmp/p/DSC*.JPG`; do
convert $file -rotate 90 file+'_rotated'.JPG
done
but that gives no output?
image manipulationimagemagickshell-scriptwildcards
I want to rotate all the images in a directory that match a pattern.
So far I have:
for file in `ls /tmp/p/DSC*.JPG`; do
convert $file -rotate 90 file+'_rotated'.JPG
done
but that gives no output?
Best Answer
There are quite a few issues with your code. First of all, you are parsing ls which is a Bad Idea. You also need to refer to the variable as
$file
as you point out and you should also quote it so it won't break on spaces. You are declaringnum
but it is never used. A safer way would be:This will still have problems if your files contain newlines but at least will not break if your path contains spaces.
If the files are all in the same directory, it can be further simplified using globbing. You can also use parameter expansion to create
foo_rotated.JPG1
instead offoo.JPG_rotated.JPG
: