title: variable reset in a bash script
body: <p>a simple variable test:</p>
  
  <pre><code>#!/bin/bash
  
  N=0
  
  ls -l | while read L; do
   N=$((N+1))
   echo $N
  done
  
  echo "total $N"
  </code></pre>
  
  <p>ran it then output:</p>
  
  <pre><code>1
  2
  3
  
  total 0
  </code></pre>
  
  <p>i expected final N=3: "total  3", but why did the value reset to 0 after the loop?</p>