title: Linux bash. for loop and function, for adding numbers
body: <p>I'm learning bash script's in Linux and I wanted to solve one problem that I thought it would be easy but I just cant figure it out.</p>
  
  <p>I want to insert number as a parameter for example:</p>
  
  <pre><code>sh script.sh 5
  </code></pre>
  
  <p>And I want to get result 15 if I insert 5 (1+2+3+4+5)=15</p>
  
  <p>I want to solve it with function.</p>
  
  <pre><code>n=$1
  result=0
  j=0
  
  ADD(){
      result=`expr $result + $j`
  }
  
  #for (( i=1; i&lt;=$n; i++ ))
  for i in {0..$n..1}
  do 
      ADD
      j=`expr $j + $1`
  done 
  
  echo $result
  </code></pre>
  
  <p>Every time when I want to add number I want to call function for adding.
  I have no idea if I even imagined right.
  And I don't know how to use for loop's. I've tried two different for loop's and I think they are not working correctly.</p>