使用 Busybox ash 进行编程时,str以下程序将按预期在每个while循环中更改,但在 while 循环之后str再次变为空。/tmp/term_mon_ttys是一个测试文件。
#!/bin/ash
cnt=0
str=
cat /tmp/term_mon_ttys | while read line; do
str="$str $cnt"
cnt=`expr $cnt + 1`
done
echo $str
但是,如果将上面的代码更改为
#!/bin/ash
cnt=0
str=
while [ $cnt -lt 5 ]; do
str="$str $cnt"
cnt=`expr $cnt + 1`
done
echo $str
然后在while循环之后, str 变为0 1 2 3 4.
有人注意到这个问题吗?