2014-09-22 35 views
-3

我想创建一个脚本,以便在一个自助服务终端时间使用。我得到的错误,意外的文件结束,并不能找出我出错的地方

以下secipt给我的错误:

“行30:语法错误:文件意外结束”

我看了一下没有结束的循环可能导致此错误,但我不能确定我的位置出错。

#!/bin/bash 

#time notifications 


while true 


xmessage "Click OK to begin your session." -buttons OK -center 

start=$SECONDS 

answer=0 

while $answer = 0 


    while [`echo "($SECONDS - $start) % 300" | bc` != 0] 

    end 

    answer=$[xmessage "You started (($SECONDS - $start)/60) minutes ago." -buttons continue:0,done:1 -center] 


end 



end 
+0

尝试使用虽然..做......做 – 2014-09-22 16:31:45

+0

/usr/src目录/计时器脚本:行20:语法错误附近意外的标记'做” – adgelbfish 2014-09-22 16:35:30

+0

也同时$答案= 0将不断地分配0到$答案,你可能想要使用比较运算符== – 2014-09-22 16:37:24

回答

1

您有一些重大的逻辑错误需要处理。我提供了一个启动会话的工作示例,并设置了10秒计时器。在每10秒钟结束时,您的消息框出现询问Continue,Done。对话轨道跟踪您使用会话的total秒。计时器被重置每次10第二阶段:

#!/bin/bash 

#time notifications 

while true; do 

    xmessage "Click OK to begin your session." -buttons OK -center 
    SECONDS=$(date +%s) 
    answer=0 
    start=$SECONDS 

    while [ "$answer" -eq 0 ]; do 
     timer=$SECONDS 

     ## temporary 10 second timer used for illustration 
     while [ $((SECONDS - timer)) -lt 10 ]; do 
      SECONDS=$(date +%s) 
      sleep 1 
     done 

     xmessage "You started $((SECONDS - start)) seconds ago." \ 
     -buttons continue:0,done:1 -center 
     answer=$? 

    done 

    [ $answer -gt 0 ] && break 

done 
相关问题