To extract the numbers from the files in your example, using native bash regex, you could do something like this:
for i in *.JPG; do
[[ $i =~ ([[:digit:]]+) ]] && echo ${BASH_REMATCH[1]}
done
Running that loop from the directory containing the files in your question would give the output:
0488
0489
0490
So if you have a tool called exif_script
that can add this information to your files, you could do something like:
for photo in *.JPG; do
if [[ $photo =~ ([[:digit:]]+) ]]; then
file_number="${BASH_REMATCH[1]}"
exif_script # set number to $file_number
fi
done
If you don't have a new enough bash to support regular expression matching, you could use sed:
for i in *.JPG; do file_number=$(echo "$i" | sed 's/[^0-9]\{1,\}\([0-9]\{1,\}\).JPG/\1/'); done
The value of $file_number
will be the same as in the first piece of code but this approach should work on the vast majority of platforms.