title: Global Variable in shell script
body: <p>I would like to make <code>z</code> a global variable in the following code:</p>
  
  <pre><code>#!/bin/bash                                                                                                                          
  z=0;
  find $1 -name "*.txt" | \
  while read file
  do
    i=1;
    z=`expr $i + $z`;
    echo "$z";
  done
  echo "$z";
  </code></pre>
  
  <p>The last statement always outputs "0". Why?</p>