我目前有一个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?
答案 0 :(得分:5)
使用$?
检查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.