gpt4 book ai didi

linux - bash,检测 mp4 文件

转载 作者:太空宇宙 更新时间:2023-11-04 09:37:16 25 4
gpt4 key购买 nike

if [ -f *.mp4 ]; then
for file in *.mp4; do
ffmpeg2theora -v 8 --nometadata "$file"
rm -f "$file"
done
fi

if [ -f *.avi ]; then
for file in *.avi; do
ffmpeg2theora -v 8 --nometadata "$file"
rm -f "$file"
done
fi

我不明白为什么 if [ -f *.mp4 ];然后 没有检测到 mp4 文件,我使用这种方法来查找 .avi、.epub、.chm 和其他一些扩展名,并且效果很好。我想知道是不是因为 4。我也尝试过 if [ -f *."mp4"];然后 但它没有用。

我觉得 for file in *.mp4; 很奇怪; do 检测 .mp4 文件,if [ -f *.mp4 ] 不检测!

最佳答案

使用 bash 选项 nullglob 允许 glob 扩展为零个元素。这样,如果没有匹配的文件,循环将不会运行:

shopt -s nullglob
for file in *.mp4; do
ffmpeg2theora -v 8 --nometadata "$file" && rm -f "$file" || \
echo Problem transcoding "$file"
done

至于[ -f *.mp4 ],它只有在只有一个匹配的文件时才能正常工作,因为那时它会扩展为[ -f myfile.mp4 ]

如果没有匹配的文件,它可能仍然有效(没有 nullglob),因为它最终会检查名称中带有星号的文件,希望它不存在。

如果有多个文件,它会失败,因为 [ -f file1.mp4 file2.mp4 file3.mp4 ] 不是有效的 test 语法。

关于linux - bash,检测 mp4 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25224324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com