日期:2014-05-16  浏览次数:20678 次

shell脚本的问题,大家帮看下。
ps -ef|grep -v "grep"|grep -v "dic.sh"|grep APPSVR|awk '{print $2}'|while read i
do
pid=$i
echo 'pid=${pid}:input "y" to kill the process of APPSVR,input "n" to continue.'
read oper
while [[ "x"$oper != "xy" && "x"$oper != "xn" ]]
do
echo 'your input is error,please input "y" or "n".'
read oper
done
if [ "$oper"x = "y"x ];then
kill -15 ${pid}
if [ $? -ne 0 ]; then
echo "kill the process of APPSVR is failed."
exit
fi
fi
done
第二个read oper的时候,oper的值总是上面结果的值,我的本意是提示我输入y或者n,要不要kill这个pid。现在根本没有提示,程序一直死循环在echo 'your input is error,please input "y" or "n".'
大家帮忙看看怎解决啊。

------解决方案--------------------
把第一个read oper删掉就行了。
------解决方案--------------------
第一个 read oper是浪费,因为你的初值肯定不会是y或n,能很顺利的进入那个while。试试吧
------解决方案--------------------
探讨
你有什么好的方法读pid吗?


引用:
刚才没看清你的shell 。 问题应该出在第一行上 为什么要用那样的方式去读一个pid呢