String Manipulation in Array of Strings with TR
<p>I am trying to automate the hashing of certain files (popular image and video formats) by using their file extension (not perfect but will suffice for my needs) recursively from the directory the script is run in.</p>

<p>I have little experience with bash and cannot figure out why this loop does not behave as intended although my suspicions are with the assignment of the <code>F_EXTENSION</code> variable and the <code>|</code> to <code>tr</code> command.  It will hash all the files in the directory regardless of their extension.  I am clearly doing something wrong.</p>

<p>The following is just a small part of the code for clarity, many more variables are assigned elsewhere (such as the filenames referenced below).</p>

<pre><code>FILES=$( find ./* -type f )
EXTENSIONS=(.jpg .gif .png .bmp .avi .mpg .mov .mkv .flv .wmv .mp4)

SAVEIFS=$IFS
IFS=$'\n'
for FILE in $FILES; do
    F_EXTENSION=${FILE: -4} | tr '[:upper:]' '[:lower:]'
    if [[ "${EXTENSIONS[@]}" =~ "${F_EXTENSION}" ]]; then
        HASH=$( md5sum $FILE )
        echo ${HASH} | cut -c1-32 &gt;&gt; ${TEMPFILE}
    else
        echo "Skipping ${FILE}" &gt;&gt; ${LOGFILE}
    fi
done
IFS=$SAVEIFS
</code></pre>

<p>After trying various methods I have to concede its time for a fresh set of eyes.  Any thoughts?</p>