title: (Bash) Dynamically save n arguments
body: <p>I was trying to find a way to dynamically store all the arguments I would pass for a shell script in an array. This would help when I have to loop trough each and every argument, to make further use of them.</p>
  
  <p><strong>This is the answer to my problem.</strong></p>
  
  <pre><code>#!bin/bash
  #Overloop alle gegeven argumenten en sla ze op in arg(plaatsvhargument)
  arr=( "$@" )
  
  #Code om te testen of het wel werkt
  y=0
  while [[ $y -lt $# ]]
  
  do
  
          val=${arr[$y]}
          echo $val
          (( y++))
  done
  </code></pre>
  
  <p>I know i could just do this, to get each and every argument out of the array. </p>
  
  <pre><code>for i in ${arr[@]}
  do
          echo $i    
  done
  </code></pre>
  
  <p>My problem is that when I run the script i end up saving the position of an argument AND I lose one argument in the process. Example:</p>
  
  <pre><code>bash testscript.sh 1 2 2 3 1  gives me 2 2 3 1 (empty)
  </code></pre>
  
  <p>What am I doing wrong, and do you guys have any fixes for my issue?</p>