title: Bash - Using a "static" variable (aka Command line Russian Roulette)
body: <p><strong>TL;DR:</strong> How do you set up a variable upon first run of a bash script and modify it upon further runs (something like a <code>static</code> variable in a function in C)?</p>
  
  <p><strong>Background info:</strong></p>
  
  <p>The following line in Bash is for playing "Command line Russian Roulette" (a much safer version of <a href="https://stackoverflow.com/a/575464/3696619">https://stackoverflow.com/a/575464/3696619</a>):</p>
  
  <pre><code>[ $[ $RANDOM % 6 ] == 0 ] &amp;&amp; echo *Boom* || echo *Click*
  </code></pre>
  
  <p>However, it doesn't really work like normal Russian Roulette (for which, within the first 6 tries, you are guaranteed to have a bullet in one of them).</p>
  
  <p>Is there any way to make sure that this occurs (i.e. a <code>*Boom*</code> is guaranteed within the first 6 tries). The code should be repeatable (i.e. exact same code should be able to be copy pasted again and again, not parts of it) and it should work properly.</p>
  
  <p>My idea is: Set up a variable that is set to <code>$[$RANDOM % 6]</code> initially and then decremented each time the code is run. If the variable reaches 0, the gun goes <code>*Boom*</code>, otherwise, it <code>*Click*</code>s. However, I am unable to figure out how to set up the variable only upon first run, and not on further runs.</p>
  
  <p><strong>Warning:</strong> Execute the code from <a href="https://stackoverflow.com/a/575464/3696619">https://stackoverflow.com/a/575464/3696619</a> only at your own risk.</p>