2012-06-15 206 views
1

在下面示出時鐘操作工作良好的Linux機器具有TCL 8.5。但是,當我在具有TCL8.4的SunOS上使用相同的命令時,出現錯誤「bad switch」-format「:must be -base or -gmt」。TCL clock命令

出於某種原因,我不能到我的TCL 8.4升級到8.5,而SunOS。

任何人都可以請大家幫忙,我怎樣才能使它在TCL 8.4工作,以及?????

的命令是下面給出我試圖通過這些命令來實現是多一天推進系統日期。

$今天包含值 「2012 06 15 14 39 20」

set today [clock scan $today -format "%Y %m %d %H %M %S"]  
set tomorrow [clock add $today 86600 seconds] 
set victim [clock format $tomorrow -format "%a"] 
set tomorrow [clock format $tomorrow -format "%m%d%H%M"] 
send "sudo date $tomorrow\r" 

感謝

回答

2

正如你所發現的Tcl 8.4和8.5之間的時鐘命令改變。在8.4中,時鐘掃描命令只識別多種標準格式。因此,您需要將您的$ today價值轉換爲其中一種格式,詳情請參閱here

一種可能的方式是

regexp {(\d\d\d\d) (\d\d) (\d\d) (\d\d) (\d\d) (\d\d)} $today all YY MM DD HH mm ss 
set reformatToday "$YY$MM$DD $HH$mm$ss" 
set today [clock scan $reformatToday] 

的Tcl 8.5也將與此自由形式掃描代碼工作;但是,此功能在8.4版以後的Tcl版本中不推薦使用。

+0

感謝插孔,我要去嘗試。 – suj

5

Jackson's answer是什麼問題的核心:8.5添加了很多功能clock和您的代碼是依賴於他們。但是,他並沒有完全確定獲得目標時間的最佳方法。

# Multiple assignment from list 
foreach {YY MM DD HH mm ss} $today break 
# Get the date tomorrow in one funky step 
set tomorrow [clock scan "$YY$MM$DD $HH$mm$ss + 86600 seconds"] 

# Rest is the same as before 
set victim [clock format $tomorrow -format "%a"] 
set tomorrow [clock format $tomorrow -format "%m%d%H%M"] 
send "sudo date $tomorrow\r" 

(你知道那一天是永遠86600秒長?這比平均長度長200秒...)

+0

這是foreach命令的一個妙用! – Jackson

+0

@傑克遜是的,但請使用8.5以後的'lassign'。 –

+0

Thx Donal。我會試試這個。順便說一句,長200秒是有意在第二天增加一些秒。 – suj