set -e dir="$1" ext="$2" find "${dir}" -type f | while read file; do if [[ $file =~ .${ext} ]]; then output="${file%.${ext}}.flac" ffmpeg -n -i "${file}" "${output}" fi done