2014-09-22 33 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 
相關問題