title: How to pass a result from a Shell Script to the next step inside Automator
body: <p>I am using automator to create a Finder service to get the length of all selected videos and display on a dialog.</p>
  
  <p>So, the service will work like this: </p>
  
  <ol>
  <li>I select a bunch of videos</li>
  <li>I right click and run the service.</li>
  </ol>
  
  <p>I have found this Bash script on the web that works perfectly.</p>
  
  <pre><code>times=()
  for f in *.mov; do
      _t=$(ffmpeg -i "$f" 2&gt;&amp;1 | grep "Duration" | grep -o " [0-9:.]*, " | head -n1 | tr ',' ' ' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
      times+=("$_t")
  done
  echo "${times[@]}" | sed 's/ /+/g' | bc
  </code></pre>
  
  <p>I am trying to adapt that for automator. So, my service so far is equal to this:</p>
  
  <p>I have a first step that receives the movie files from Finder and passes to this <code>Run Shell Script</code></p>
  
  <pre><code>times=()
  for f in "$@"; do
      _t=$(ffmpeg -i "$f" 2&gt;&amp;1 | grep "Duration" | grep -o " [0-9:.]*, " | head -n1 | tr ',' ' ' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
      times+=("$_t")
  done
  total="${times[@]}" | sed 's/ /+/g' | bc
  </code></pre>
  
  <p>I was forced to change the <code>for</code> loop to this</p>
  
  <pre><code>for f in "$@"; do
  </code></pre>
  
  <p>I understand this is how automator enumerates all files received. Files are received as arguments.</p>
  
  <p>I have changed the last line to</p>
  
  <pre><code>total="${times[@]}" | sed 's/ /+/g' | bc
  </code></pre>
  
  <p>To create a variable called <code>total</code> that can hold the total number of seconds of all videos.</p>
  
  <p>Now I need to pass this variable to the next step and display it on a dialog.</p>
  
  <p>Two questions:</p>
  
  <ol>
  <li>how do I do that?</li>
  <li>are the changes I did correct?</li>
  </ol>
  
  <p>thanks</p>