title: Want to check whether a command succeeded by redirecting its output to a variable
body: <p>I'm currently writing a bash script which loads video files up to to YouTube using <a href="http://code.google.com/p/googlecl/" rel="nofollow noreferrer">GoogleCL</a>.</p>
  
  <p>As I'm doing this uploading stuff in a loop (because there can be multiple video files) I would like to check if each file had been uploaded successfully before I upload the next one.</p>
  
  <p>The command <code>google youtube post --access unlisted --category Tech $f</code> (where $f represents the file) outputs a string which tells me whether the upload has been successful or not.</p>
  
  <p>But I don't know how to redirect that "return string" into a variable to do check the successs.</p>
  
  <p>That's what I have:</p>
  
  <pre><code>for f in ./*.ogv ./*.mov ./*.mp4
  do
      if [[ '*' != ${f:2:1} ]]
      then
          echo "Uploading video file $f"
  
          # How to put the return value of the following command into a variable?
          google youtube post --access unlisted --category Tech $f &gt; /dev/null
  
          # Now I assume that the output of the command above is available in the variable RETURNVALUE
          if [[ $RETURNVALUE == *uploaded* ]]
          then
              echo "Upload successful."
          else
              echo "Upload failed."
          fi
      fi
  done
  </code></pre>
  
  <p>Can anybody help me?</p>