title: Go os.Exit(2) show a bash $? value of 1
body: <p>I wrote a short Go program using <code>os.Exit(2)</code> and ran this from a Bash shell.</p>
  
  <p>When I type <code>echo $?</code> it shows a values of <code>1</code> regardless of the exit value passed to <code>os.Exit</code>.</p>
  
  <p>The Bash script below shows a <code>$?</code> value of <code>2</code> as does the C program.</p>
  
  <p>Why does the Go program always show a value of <code>1</code>? How can I exit with a code other than <code>0</code> or <code>1</code>, and should I use this method to indicate differing exit states?</p>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import "os"
  
  func main() {
      os.Exit(2)
  }
  </code></pre>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  
  exit 2
  </code></pre>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdlib.h&gt;
  
  int main() {
      exit(2);
  }
  
  </code></pre>