I originally had a set of images of the form image_001.jpg, image_002.jpg, ...
I went through them and removed several. Now I\'d like to rename the leftover files ba
Some good answers here already; but some rely on hiding errors which is not a good idea (that assumes mv
will only error because of a condition that is expected - what about all the other reaons mv
might error?).
Moreover, it can be done a little shorter and should be better quoted:
for file in *; do
printf -vsequenceImage 'image_%03d.jpg' "$((++i))"
[[ -e $sequenceImage ]] || \
mv "$file" "$sequenceImage"
done
Also note that you shouldn't capitalize your variables in bash scripts.