Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to batch convert a bunch of files and i am doing an simple listing of the converted files to a text document so that i can stop the script and continue from approximately were i started.

#! /bin/sh

find $source_dir -type f -regex ".*/.*\.\(mov\|mpg\|mkv\|avi\|m2v\|wmv\|flv\|m2ts\|vob\)" | {
while read file
  touch converted.txt

  if grep -Fxq "$filename" converted.txt
    echo "$(tput setaf 2)File "$filename" is allready converted, ignoring it :D$(tput setaf 7)"
    # Extract subtitles for mkv files
    echo $ext
    if [ "$ext"=="mkv" ]; then
      # <- default subtitle
      # <- other languages
      mkvinfo=$(mkvinfo $file | grep subtitles -B3 -A3)

      # Replace existing .srt
      # rm $dirname/$

      # Extract subtitle from mkv
      # mkvextract tracks input.mkv -c ISO8859-1 3:$dirname/$basename.$

    avconv -y -i $file -map 0 -map -0:s -vcodec libx264 -acodec libfaac $dirname/$basename.mp4

    # Store the filename in list
    echo $filename >> converted.txt

There you go, subtitle extraction is also in progress but i am having trouble with knowing if avconv fails or not, is there a way?

Edit Somewhat done with this script now, here it is thanks for the help!

share|improve this question
up vote 3 down vote accepted

Most commands return a non-zero return value if an error occurred. You can either capture that return code or act on it with via || and &&.


avconv -y -i file1 ; echo command finished

avconv -y -i file1 && echo command finished successfully.

avconv -y -i file1 || echo command finished but indicated failure!


You can also check $? in the shell. example:

echo $?
echo $?

True always succeeds. If you run the test script it will return a 0.
False always fails. If you run the test script it will return a non-0. (in my case a 1, but that can vary).

share|improve this answer
Hey that worked! – eldamar Feb 3 '13 at 15:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.