How can I do foreach *.mp3 file recursively in a bash script?

后端 未结 5 1350
你的背包
你的背包 2020-12-09 19:53

The following works fine within the current folder, but I would like it to scan sub folders as well.

for file in *.mp3

do

echo $file

done
5条回答
  •  情书的邮戳
    2020-12-09 20:26

    Sounds like you are looking for the find command. I haven't tested this, but something along these lines:

    files=(`find . -name *.mp3`)
    for file in "${files[@]}"; do
        echo $file TITLE="id3info "$file" | grep '^=== TIT2' | sed -e 's/.*: //g'" ARTIST="id3info "$file" | grep '^=== TPE1' | sed -e 's/.*: //g'"
    done
    

    EDIT: using the array makes the command safe for files with spaces in their names.

提交回复
热议问题