close-brace后的tcl额外字符

时间:2015-01-15 12:25:17

标签: awk grep character tcl

我有这个错误Tcl错误:close-brace之后的额外字符

proc exact {nick host handle channel text} {
global db_handle network;

set size exec curl -3 --ftp-ssl -k ftp://xxx:xxx@192.210.0.8:2300/source/ | grep \\.r | awk '{print $5}'| awk '{ SUM += $1} END { print SUM/1024/1024 }'

putnow "PRIVMSG #chnnel :source has $size"
}

1 个答案:

答案 0 :(得分:3)

根据exec(n) man page,你需要用花括号替换单引号。您还需要在[]周围exec来调用它:

    set size [exec curl -s -3 --ftp-ssl -k {ftp://xxx:xxx@192.210.0.8:2300/source/} | grep \\.r | awk {{print $5}} | awk {{ SUM += $1} END { print SUM/1024/1024 }}]

也就是说,您根本不需要调用grepawk。你在这里用它们做的一切都可以在Tcl代码中完成:

proc exact {nick host handle channel text} {
    global db_handle network;

    set status 0
    set error [catch {
        set resp [exec curl -s -3 --ftp-ssl -k {ftp://xxx:xxx@192.210.0.8:2300/source/}]
    } results options]
    if {$error} {
        set details [dict get $options -errorcode]
        if {[lindex $details 0] eq "CHILDSTATUS"} {
             set status [lindex $details 2]
             putnow "PRIVMSG $channel :curl error $status"
        }
    }
    set size 0
    foreach line [split $resp \n] {
        if {[string match {*\\.r*} $line]} {
            incr size [lindex $line 4]
        }
    }

    putnow "PRIVMSG $channel :source has [expr {$size/1024/1024}]"
}

(我认为你的意思是$channel而不是#chnnel。)