我的脚本bash中有一个奇怪的行为。当while条件为true时,脚本行为正确,但如果为false,则循环后的命令根本不执行,脚本停止。循环后我的命令没有中断。 我看不出问题出在哪里!欢迎任何帮助:) 提前谢谢。
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..
答案 0 :(得分:2)
此脚本中存在许多错误:
$
grep Start_t $job_template | awk -F= '{print $2}'
和awk -F= '/Start_t/{print $2}' $job_template
会做同样的事情。