title: How to limit number of iterations in a for loop in shell script
body: <p>I am working on a shell script to fetch data from DB and return results based on the input provided by user.</p>
  <p>However I would like to limit the user to pass Maximum of a specific number (for eg. 10) comma separated values. Even if user has passed more than 10 values, my shell script should restrict the user and execute only 10 from the user provided list.</p>
  <p>I'm able to fetch results for all user provided values, But not able to make out how to limit the same to a specific number.</p>
  <h2>My Shell Script</h2>
  <pre><code>IDs=a1,b2,c3,d4,e5,f6,g7,h8,i9,j10,k11,l12,m13,n14
  # Above are User provided sample alphanumeric values
  
  for i in $(echo $IDs | sed &quot;s/,/ /g&quot;)
  do
    echo &quot;Fetching results for $i by running sql against DB&quot;
  done
  </code></pre>
  <h1>Expecting Results</h1>
  <p>I except shell script to fetch only first 10 comma separated values by ignore rest (In above eg. script need to pick values until from &quot;a1&quot; to &quot;j10&quot; and ignore rest) and execute the same against DB.</p>
  <p>Any help would be greatly appreciated. Thanks in advance!</p>