title: How to loop through array items and pass each item to a function in bash
body: <p>How can I pass a single item value from array starting from index/item 0 into function and loop through the array until all items have been passed?</p>
  
  <p>This scripts intended purpose is to pull lines from a text file called array_list and pass them into an array, then perform a function on each array item in a loop until all items have been passed and echo out results to a text file called results.txt showing HTTP Status Codes to associated URL's</p>
  
  <pre><code>#!/bin/bash
  #
  #Script to lookup URL address and capture associated HTTP Status Code (EG: 200, 301, 400, 404,500, 503)
  #
  #
  declare -a array
  array=()
  getArray()
      {
      i=0
      while read line
      do
          array[i]=$line
          i=$(($i + 1))
      done &lt; $1
      }
  getArray "array_list"
  for url in ${array[@]}
  do
      function call()
      {
          curl -s -o /dev/null -w "%{http_code}" $url
      }
  done
  
  response=$(call)
  
  echo $url $response  &gt;&gt; result.txt
  </code></pre>