gpt4 book ai didi

bash - 仅当循环的第一步没有错误时,如何使 bash 脚本继续循环的一部分?

转载 作者:行者123 更新时间:2023-12-04 22:52:08 25 4
gpt4 key购买 nike

我目前有一个适用于 Mac 的 .command 文件,其中包含以下内容:

for f in ~/Desktop/Uploads/*.flv
do
/usr/local/bin/ffmpeg -i "$f" -vcodec copy -acodec libfaac -ab 128k -ar 48000 -async 1 "${f%.*}".mp4
rmtrash "$f"
done

如果 ffmpeg 不产生错误,我如何告诉 bash 只执行 rmtrash?

最佳答案

使用 $? 检查 ffmpeg 命令的返回值或把 &&在这样的两个命令之间:

for f in ~/Desktop/Uploads/*.flv
do
/usr/local/bin/ffmpeg -i "$f" -vcodec copy -acodec libfaac -ab 128k\
-ar 48000 -async 1 "${f%.*}".mp4 && rmtrash "$f"
done

根据 bash 手册:
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.

关于bash - 仅当循环的第一步没有错误时,如何使 bash 脚本继续循环的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9950431/

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