Shell 我如何使用更新的变量,它在while循环内部,在while循环外部

Shell 我如何使用更新的变量,它在while循环内部,在while循环外部,shell,Shell,##我想在最后打印更新后的数组,但由于它位于while循环(子shell)内,因此无法将其发送到while循环外部,也无法将更新后的数组传递到while循环外部。下面是我的代码。我想打印“数组变量” declare-a变量 计数器=0 #设置警戒级别 警报=25 读取输出时,df-H | grep-vE ^ Filesystem | tmpfs | overlay | cdrom | awk{print$5“$1}”; 做 #回显使用百分比和装入点 usagePercent=$(echo$out

##我想在最后打印更新后的数组,但由于它位于while循环(子shell)内,因此无法将其发送到while循环外部,也无法将更新后的数组传递到while循环外部。下面是我的代码。我想打印“数组变量”

declare-a变量
计数器=0
#设置警戒级别
警报=25
读取输出时,df-H | grep-vE ^ Filesystem | tmpfs | overlay | cdrom | awk{print$5“$1}”;
做
#回显使用百分比和装入点
usagePercent=$(echo$output | awk'{print$1}'| cut-d''''-f1)
mountP=$(echo$output | awk'{print$2}')
如果[$usagePercent-ge$ALERT];然后
#计数器=$(expr$计数器+1)
#回声计数器
#echo$mountP
变量[计数器]=$mountP
#echo${var[0]}
计数器=$(expr$计数器+1)
fi
#回显“数组${var[@]}”
完成
**echo“array${var[@]}”**。从
declare -a var
counter=0
# set alert level
ALERT=25
df -H | grep -vE '^Filesystem|tmpfs|overlay|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  #echo usagepercentage and mount point
  usagePercent=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  mountP=$(echo $output | awk '{ print $2 }' )
  if [ $usagePercent -ge $ALERT ]; then
#   counter=$(expr $counter + 1)
#   echo $counter
#   echo $mountP
   var[counter]=$mountP
#   echo ${var[0]}
   counter=$(expr $counter + 1)
  fi
#echo "Array ${var[@]}"
done
**echo "array ${var[@]}"**  << NO OUTPUT from this