title: bash scripting reading numbers from a file
body: <p>Hello i need to make a bash script that will read from a file and then add the numbers in the file. For example, the file im reading would read as:</p>
  
  <p>cat samplefile.txt</p>
  
  <pre><code> 1
   2
   3
   4
  </code></pre>
  
  <p>The script will use the file name as an argument and then add those numbers and print out the sum. Im stuck on how i would go about reading the integers from the file and then storing them in a variable. 
  So far what i have is the following:</p>
  
  <pre><code>#! /bin/bash
  
  file="$1"   #first arg is used for file
  sum=0       #declaring sum
  readnums    #declaring var to store read ints
  
  if [! -e $file] ; do     #checking if files exists
      echo "$file does not exist"
      exit 0
  fi
  
  while read line ; do
  
  do &lt; $file
  
  exit 
  </code></pre>