#!/bin/sh

image_ext='png|gif|jpe?g$'

for i in *; do
	type=$(file -b --mime-type "$i" | grep -Eo "/$image_ext/" | tr -d '/' | sed -e 's/jpeg/jpg/')

	# Add respective file-extension if needed.
	[ $type ] && {
		mv $i $(echo $i | sed -Ee "s/\.($image_ext)//")".$type" || {
			tput setaf 9;
			>&2 printf 'Could not rename file "%s".\n' $(basename $i);
			tput sgr0;
		};
	};

done;

Add script for appending image file extensions
Add script for appending image file extensions

Batch-downloading a colossal bunch of images tonight left me with 10,000
images saved without file extensions, each of potentially varying types.
Obviously a shell-script was needed to properly survey the contents, so
here we are. Can't see this script seeing frequent use, but it might be
helpful again in future.
