#!/usr/bin/env bash # Go through files with the bmp case insensitive file extension under the current directory find . -iname '*bmp' -print0 | while read -rd $'\0' f; do # Replace the file extension "bmp" with "jpg" z=$(echo $f | sed 's/bmp/jpg/gi') # Run the convert utility, which comes with the imagemagick suite of stuff convert $f $z # If the exit code is zero, then it worked if [ "$?" -eq 0 ]; then echo Converted $f to $z # Otherwise it didn't else echo Failed converting $f to $z fi done