'Why is my JPEGOptim Shell Script not working after upgrading to Macbook Pro M1 Max?

I am using Automator on a Mac M1 to bulk/batch compress images. This script is working fine on my older Macs. How come they do not work anymore?

JPEGOptim is installed. Automator says the Workflow has been completed, but there is no change to the actual files 🤔

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

BIN_PATH=~/Library/Services/.bin

for f in "$@"; do
    if [ -d $f ]; then
        echo "TODO: nothing to compress now!"
    elif [[ $f == *.png ]]; then
        if hash optipng 2>/dev/null; then
            optipng -o7 "$f"
        else
            $BIN_PATH/optipng -o7 "$f"
        fi
        if hash pngcrush 2>/dev/null; then
            pngcrush -brute -reduce -ow "$f"
        else
            $BIN_PATH/pngcrush -brute -reduce -ow "$f"
        fi
    elif [[ $f == *.jpg ]]; then
        if hash jpegoptim 2>/dev/null; then
            jpegoptim "$f" --strip-all --force --all-progressive --size=150k
        else
            echo "No jpegoptim installed, skipped."
        fi
    elif [[ $f == *.svg ]]; then
        if hash svgo 2>/dev/null; then
            svgo "$f"
        else
            echo "No SVGO installed, skipped."
        fi
    else
        echo "TODO: nothing to compress now!"
    fi
done;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source