#!/bin/bash appdir=$1 if [ -z "$appdir" ]; then echo "usage: $0 " exit 1 fi function copylibs() { DLLFILE=$1 echo "Checking: $DLLFILE" ldd $DLLFILE | grep '/mingw64/bin' | awk '{print $1}' | uniq | while read line; do cp -v /mingw64/bin/$line $appdir done } find "$appdir" -type f -name '*.dll' | while read line; do copylibs $line done