Are you sure ffmpeg was finished before your deleted its input? It sounds like it was just taking longer than you expected. If that's not it, I don't know. The script doesn't look obviously wrong to me, but you're complicating this more than you need to, and simplifying is often an easier way to fix bugs than figuring out why the complicated thing isn't working. For looping over files in the current directory you want for and a glob: do ... done will loop over just the subdirectories of the current directory. */ only matches directories, so you don't need the test. Using a subshell to reset the current working directory is going around the world. pushd/popd are what you want. Try do pushd "$d" ffmpeg -f concat -i mylist.txt -threads 35 -c copy concat.avi popd done Since you're not doing set -e you don't need to worry about ffmpeg failing and leaving you in the last directory the script was working on when it failed. for d in */
for d in */