我的脚本 bash 中有一个奇怪的行为。当 while 条件为真时,脚本行为正确,但如果为假,则根本不执行循环后的命令并且脚本停止。循环后我的命令没有中断。我看不出问题出在哪里!欢迎任何帮助:) 提前致谢。
while [ expression1 ] || [ expression2 ]
do
echo in the loop
if [ expression3 ] && [ expression4 ] ;
then
commands..
break;
fi
commands..
done
commands..
echo out from the loop
真实代码:
start_t=`grep Start_t $job_template | awk -F= '{print $2}'`
current_date=`date +%s`
progress_t=`expr $current_date - $start_t`
exec_t=`grep Exec_t $job_template | awk -F= '{print $2}'`
running_state="r"
req_state $job_id # get the state
xml_state=` grep "job_id=$job_id" $list_job_file | awk '{print $4}'`
while [ $state = $running_state ] || [ $xml_state = "stoped" ]
do
echo in the loop
if [ "$xml_state" = "running" ] && [ $progress_t -gt $exec_t ] ;
then
kill_job $job_id
update_status $job_template "killed"
echo The job is killed
break;
fi
sleep $sleeping_t
$req_state $job_id # to update the state
echo state $state
xml_state=` grep "job_id=$job_id" $list_job_file | awk '{print $4}' `
echo xml_state $xml_state
start_t=`grep Start_t $job_template | awk -F= '{print $2}'`
current_date=`date +%s`
progress_t=`expr $current_date - $start_t`
done
echo out from the loop
commands..