Search code examples
sshsynology

Loop through files on Synology SSH command line


I have Synology with ipkg installed, and mkvmerge working.

When I use

/opt/bin/mkvmerge -o /path_to_file/filename.added_subs.mkv 
--default-track 0 --language 0:eng /path_to_file/filename.srt     
/path_to_file/filename.mkv

This works perfectly, and the file gets remuxed with the subtitles added.

But because I have many (many) files I want to do this with, I;d like to run a batch for this.

I've found this line to explain what I want to do:

FOR %A IN (/path_to_files/*.mkv) DO /opt/bin/mkvmerge -o /path_to_files/%~nA.added_subs.mkv --default-track 0 --language 0:eng /path_to_files/%~nA.srt /path_to_files/%~nA.mkv

But the Synology won't accept the FOR ... IN command.

Anyone have an idea how to accomplish this?


Solution

  • Found it:

    FILES=/path/*.mkv
    for f in $FILES 
    do /opt/bin/mkvmerge -o ${f%.*}.EN.mkv --default-track 0 --language 0:en ${f%.*}.srt ${f%.*}.mkv
    done