1

I currently have a .command file for Mac that contains the following:

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

How can I tell bash to only execute rmtrash if ffmpeg doesn't produce an error?

1 Answer 1

5

Check for return value of ffmpeg command using $? or put && between 2 commands like this:

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

As per the bash manual:

command1 && command2
   command2 is executed if, and only if, command1 returns an exit status of zero.
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the help. Will this continue the loop if one file fails but there are more to convert?
Yes it will continue to loop.
Wonderful! Thanks for the quick response. Off to converting!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.