Bash Shell 计算 MAC 中文件夹内所有视频持续时间的总和 OS

Bash Shell Calculating Sum of All Video durations inside a folder in MAC OS

我以前只通过搜索 *.mp4 和 select 所有文件就可以在 windows 中得到我的结果。持续时间的总和将显示在侧面板的详细信息中。我想递归地在 MAC 中找到相同的东西。 这是我在bash写的脚本。告诉我我做错了什么?

#!/bin/bash
sum=0
find .  -type f -name "*.mp4" | while read line; do
    duration=`mdls -name kMDItemDurationSeconds "$line" | cut -d "=" -f 2`
    sum=$(echo "$duration + $sum"|bc)
all=$sum
done
echo $all
#!/bin/bash
sum=0
while read line; do
    duration=$(mdls -name kMDItemDurationSeconds "$line" | cut -d "=" -f 2)
    sum=$(echo "$duration+$sum"|bc)
done <<< "$(find .  -type f -name "*.mp4")"
h=$(bc <<< "$sum/3600")
m=$(bc <<< "($sum%3600)/60")
s=$(bc <<< "$sum%60")
printf "%02d:%02d:%05.2f\n" $h $m $s

我的方案,还不完善