title: How do I rotate a list of variables in bash so each time the script is run, it chooses the next variable?
body: <p>So when my script runs, I need to choose the next variable in line that is after the one that ran on the previous script run.</p>
  
  <p>Here's what I need to have happen</p>
  
  <p><strong>Script Run #1</strong></p>
  
  <pre><code>var=(Run1 Run2 Run3)
  echo ${var[0]}
  
  OUTPUT: Run1
  </code></pre>
  
  <p><strong>Script Run #2</strong></p>
  
  <pre><code>var=(Run1 Run2 Run3)
  echo ${var[1]}
  
  OUTPUT: Run2
  </code></pre>
  
  <p><strong>Script Run #3</strong></p>
  
  <pre><code>var=(Run1 Run2 Run3)
  echo ${var[2]}
  
  OUTPUT: Run3
  </code></pre>
  
  <p>Then when the script runs on the 4th time, it should go back to the first variable and repeat the rotating process.</p>
  
  <p><strong>Script Run #4</strong></p>
  
  <pre><code>var=(Run1 Run2 Run3)
  echo ${var[0]}
  
  OUTPUT: Run1
  </code></pre>
  
  <hr>
  
  <p>Now before this, I have just been using sort of a bad method of choosing a random variable when the script starts, but I'm trying to do it properly now. Here's how I was doing it before:</p>
  
  <p><strong>Script Run #1</strong></p>
  
  <pre><code>rndNum = $(( $RANDOM % 3 ))
  var=(Run1 Run2 Run3)
  echo ${var[$rndNum]}
  
  OUTPUT: Run3
  </code></pre>
  
  <p><strong>Script Run #2</strong></p>
  
  <pre><code>rndNum = $(( $RANDOM % 3 ))
  var=(Run1 Run2 Run3)
  echo ${var[$rndNum]}
  
  OUTPUT: Run1
  </code></pre>
  
  <p>and so on...</p>
  
  <p>Sorry if this is a  bad question, I am very new to bash.</p>
  
  <p>Thanks!</p>