Local variables after loop exit

前端 未结 5 672
眼角桃花
眼角桃花 2021-01-03 13:50

I am having some issues with local variables after exiting a loop. The variable max ends up with the value 0, despite the code below:

max=0
cat          


        
5条回答
  •  [愿得一人]
    2021-01-03 14:09

    max=0
    while read line
    do
        temp=$(echo $line|tr -d "\n"|wc -c)
        if [ $temp -gt $max ]
        then 
            max=$temp
            echo $max
        fi
    done 

提交回复
热议问题