shell脚本中的全局变量

Viv*_*oel 4 bash shell

我想z在以下代码中创建一个全局变量:

#!/bin/bash                                                                                                                          
z=0;
find $1 -name "*.txt" | \
while read file
do
  i=1;
  z=`expr $i + $z`;
  echo "$z";
done
echo "$z";
Run Code Online (Sandbox Code Playgroud)

最后一个语句总是输出"0".为什么?