Reputation: 111
I need to create a shell script that create thumbnails of files in a certain directory, but exclude those that already is created. The original files is named using a five digit number .jpg. Eg. 13993.jpg. Th thumbnails is named 13993_thumb.jpg. The code below is what i have started with bu I am not able to find the matching pattern... Any suggestions?
#!/bin/bash
for i in *.jpg
do
echo "Prcoessing image $i ..."
[[ $i == "0-9_thumb.jpg"* ]] && continue
# /usr/bin/convert -thumbnail 200 $i thumb.$i
done
Upvotes: 0
Views: 990
Reputation: 180
Better use the power of utils and pipes:
$ ls *.jpg
11223.jpg 12345_thumb.jpg 42424.jpg 99999_thumb.jpg
$ ls *.jpg | grep -v '^[0-9]\{5\}_thumb\.jpg' | while read f; do echo convert $f ... ; done
convert 11223.jpg ...
convert 42424.jpg ...
Regular expression in your case:
[[ "12345_thumb.jpg" =~ ^[0-9]{5}_thumb\.jpg$ ]]
Upvotes: 1
Reputation: 784888
You are not using correct glob pattern.You need to use:
[[ "$i" == [0-9]*"_thumb.jpg" ]] && continue
[0-9]*
will match 1 or more digitsUpvotes: 0