【发布时间】:2011-12-13 01:40:42
【问题描述】:
退出循环后,我遇到了一些局部变量问题。尽管有以下代码,变量max 的最终值为 0:
max=0
cat tmp|while read line
do
temp=$(echo $line|tr -d "\n"|wc -c)
if [ $temp -gt $max ];then
max=$temp
echo $max
fi
done
echo -n tmp $max
cat tmp
12345
123456
这是我收到的输出:
5
6
tmp 0
我不明白为什么 max 在退出循环后为 0,而在循环内它找到了正确的值。
【问题讨论】:
-
我认为这篇文章解决了这个问题:linuxforums.org/forum/linux-programming-scripting/…
标签: bash