title: Linux Bash Shell Custom Error Message
body: <p>I'm trying to spew a custom error message using the following 1 liner bash shell command.  I'm not getting the "errorMessage" var set.  However if I run the command individually, I'm able to capture the error message into $errorMessage variable. <strong>What am I missing?</strong></p>
  
  <p><strong>Command:</strong></p>
  
  <pre><code>[ "errorMessage=$(mkdir -p /path/to/restricted/folder 2&gt;&amp;1)" ] &amp;&amp; echo "Something Went Wrong; Error is: ${errorMessage}"
  </code></pre>
  
  <p><strong>Trials/Output:</strong> </p>
  
  <pre><code>$ [ "errorMessage=$(mkdir -p /path/to/restricted/folder 2&gt;&amp;1)" ] &amp;&amp; echo "Something Went Wrong; Error is: ${errorMessage}"
  Something Went Wrong; Error is:
  $ echo $errorMessage
  
  $ errorMessage=$(mkdir -p /path/to/restricted/folder 2&gt;&amp;1)
  $ echo $errorMessage
  mkdir: cannot create directory `/path': Permission denied
  </code></pre>