title: Programatically cycle through arguments given to a script or function
body: <p>I'm trying to cycle through an unknown number of arguments given to a bash script (or function within), to effectively handle the odds (<code>$1</code>, <code>$3</code>, etc.) and evens (<code>$2</code>, <code>$4</code>, etc.) in different ways.  </p>
  
  <p>I know I can get the number of arguments using <code>$#</code>, and the arguments themselves using <code>$@</code>, and of course <code>echo $1 $2</code> or <code>printf '%s\n' "$1"</code> both work.   What I'm needing to do is effectively echo the odds <code>echo $1 $3 $5 ...</code> with an unknown number, then separately deal with the evens, and count the characters of these individually also, so need to get these programmatically if at all possible.</p>
  
  <p><strong>Note:</strong> Some of the input will have spaces, but where will always have quotes.  An example would be <code>1 "This one" "Another one" "and another" "last one"</code>.</p>
  
  <p>I've tried (these are just to get output for brevity):</p>
  
  <p>Putting <code>$@</code> into an array of itself, in both for and while arrangements (understanding this zero indexes the array):</p>
  
  <pre class="lang-sh prettyprint-override"><code>indexedarray="$@"
  for i in {0..$#..2}; do #This in itself creates an error ({0..5..2}: syntax error: operand expected (error token is "{0..5..2}")).
    echo -n "${indexedarray[$i]}
  done
  </code></pre>
  
  <p>This produces empty output:</p>
  
  <pre class="lang-sh prettyprint-override"><code>i=0
  while [ $i -lt $# ]; do
      echo ${INDEXEDARRAY[i]}
      ((i+2))
  done
  </code></pre>
  
  <p>And the (somewhat) obvious foibles inside of for or while loops:</p>
  
  <pre class="lang-sh prettyprint-override"><code>  echo "${$@[$i]}"
    echo $"${i}"
  </code></pre>
  
  <p>None of which work.</p>
  
  <p>Any ideas on how I might improve this, and get the output I need?</p>