title: How to get kill command result in bash script
body: <p>I have a bash script which run a command to get its result and do something depends on the result. Here is the script:</p>
  
  <pre><code>#!/bin/bash
  commandResult=$(($myCommand) 2&gt;&amp;1)
  if [[ "$commandResult" == *Error* ]]; then 
      x="failed"
  else
      x="success"
  fi
  echo $x
  exit 0;
  </code></pre>
  
  <p>There is no problem with this script, the issue is when I try to kill <code>$myCommand</code> in the middle of running the script via <code>kill -9 $myCommand</code> in command line, the <code>$commandResult</code> will be null and the "success" will be printed.</p>
  
  <p>How could I put the kill result in the <code>$commandResult</code> or any other way to find out if process killed in this script?</p>
  
  <p>Any help would be much appreciated. </p>