title: Why is exit my status valid in command line but not within bash script? (Bash)
body: <p>There are a few layers here, so bear with me.</p>
  
  <p>My <code>docker-container ssh -c"echo 'YAY!'; exit 25;"</code> command executes <code>echo 'YAY!'; exit 25;</code> in my docker container. It returns:</p>
  
  <pre><code>YAY
  error:  message=YAY!
  , code=25
  </code></pre>
  
  <p>I need to know if the command within the container was successful, so I append the following to the command:</p>
  
  <pre><code>docker-container ssh -c"echo 'YAY!'; exit 25;"  &gt;&amp;1 2&gt;/tmp/stderr; cat /tmp/stderr | grep 'code=' | cut -d'=' -f2 | { read exitStatus; echo $exitStatus; }
  </code></pre>
  
  <p>This sends the <code>stderr</code> to /tmp/stderr and, with the <code>echo $exitStatus</code> returns:</p>
  
  <pre><code>YAY!
  25
  </code></pre>
  
  <p>So, this is exactly what I want. I want the $exitStatus saved to a variable. My problem is, I am placing this into a bash script (GIT pre-commit) and when this exact code is executed, the exit status is <code>null</code>.</p>
  
  <p>Here is my bash script:</p>
  
  <pre><code># .git/hooks/pre-commit
  
  if [ -z ${DOCKER_MOUNT+x} ];
  then
      docker-container ssh -c"echo 'YAY!'; exit 25;"  &gt;&amp;1 2&gt;/tmp/stderr; cat /tmp/stderr | grep 'code=' | cut -d'=' -f2 | { read exitStatus; echo $exitStatus; }
  
      exit $exitStatus;
  else
      echo "Container detected!"
  fi;
  </code></pre>