How to search a digit i.e process id in tcl and kill the process id

前端 未结 4 938
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 09:48

I have tried to search process id i-e 6762 stored in a variable say buffer

nohup tcpdump -ni  eth0 -s0  2>&1          


        
4条回答
  •  日久生厌
    2021-01-27 10:48

    It is important to put spaces and braces in in Tcl because each word to a command needs to be properly separated from all the others and end-of-line signals end-of-command unless you quote or escape it.

    Thus, your code:

    foreach line [split $buffer "\n"]{
        if {[regexp {\[\d\]\s+(\d+)}$line junk pid]}
           break
    }
    

    That has a problem in that there's no space between ] and { on the first line, a problem in that there's no space between } and $ on the second line, and a problem that there's nothing to make the third line associated with the second. Let's write it to be conventional Tcl:

    foreach line [split $buffer "\n"] {
        if {[regexp {\[\d\]\s+(\d+)} $line junk pid]} {
            break
        }
    }
    

    I've changed almost nothing; just added some spaces and some braces.

提交回复
热议问题