title: Capturing output and exit codes in BASH / SHELL
body: <p>I am having trouble capturing output and exit codes inside a shell.</p>
  
  <p>I need to compare exit codes from 2 scripts and if they don't match I want to echo the output of my 2 scripts.</p>
  
  <p>What I currently have:</p>
  
  <pre><code>#!/bin/bash
  
  resultA=$(./a.out 2&gt;&amp;1)
  exitA=$?
  resultB=$(./b.out 2&gt;&amp;1)
  exitB=$?
  </code></pre>
  
  <p>Problem is a possible Segmentation Fault message is not captured, because it is directed to the error output of my current shell, but I need to capture everything including something like Segmentation Faults.</p>
  
  <p>What is kind of a workaround and not as detailed as the real message:</p>
  
  <pre><code>#!/bin/bash
  
  resultA=$(./a.out 2&gt;&amp;1)
  exitA=$?
  resultB=$(./b.out 2&gt;&amp;1)
  exitB=$?
  if [ $exitA == 139 ]; then
      resultA=$resultA"Segmentation Fault"
  fi
  </code></pre>
  
  <p>This makes the words segmentation fault at least appear in my result variables.</p>