title: Getting the output of the previous command in shell script
body: <p>I have the following shell script:</p>
  
  <pre><code>#!/usr/bin/env sh
  ./node_modules/.bin/nightwatch --env chrome --tag=enabled
  exit 0
  </code></pre>
  
  <p>The <code>nightwatch</code> command always returns the <code>exit code 1</code>, doen’t matter if the nightwatch tests will fail or pass. So, I want to check if the console output of this command contains a specific string (maybe <code>failed</code>) to handle on it and to return a right exit code with the shell script.</p>
  
  <p>The only requirement I have is, that the nightwatch command output is visible on console because we will need it because of debugging reasons.</p>
  
  <p>I want to do something like this (pseudo code):</p>
  
  <pre><code>#!/usr/bin/env sh
  ./node_modules/.bin/nightwatch --env chrome --tag=enabled
  if lastOutput.contains("failed"); then
    exit 1
  else
    exit 0
  fi
  </code></pre>