#!/bin/bash for d in ./*; do if [ -d "$d" ]; then f=${d:2} cd "$d" echo ${f}.mp3 # find all mp3s, sort them (e.g. 100 after 99, not after 10), # get only filenames, handle spaces, and pass list to mp3cat find . -iname "*.mp3" -exec basename {} \; | sort -h | xargs -d '\n' mp3cat -c 1 -o "${f}.mp3" # mp3cat -c 1 ./*.mp3 -o "${f}.mp3" mv "${f}.mp3" ../ cd .. fi done