This does the cd in a subshell and is using GNU uniq because of the -z
#!/usr/bin/env bash
shopt -s nullglob
input_dir=$1
output_dir=$2
mkdir -p "$output_dir"
while IFS= read -rd '' dir; do
files=("$dir"/*.mp3)
if (( ${#files[*]} )); then
(
cd "$dir" || exit
output_file=$out_putdiroutput_file=$output_dir/${PWD##*/}
echo " Output: $output_file"
echo sox --show-progress "${files[@]##*/} "$output_file"
)
fi
done < <(find "$input_dir" -type d -print0 | uniq -z)
- Remove the
echobefore thesoxIf you think the output is correct. - I have never used
soxbefore just so you know.