Tcl脚本:从文件读入一行并处理的框架

#!/bin/sh
#/
exec expect "$0" "$@"

 

set timeout 15
#log_user 0

proc printf {msg} {
  global argv0
  puts "$argv0: $msg"
}

#main function
set fname [lindex $argv 0]
if {! [file exists $fname]} {
 printf "file '$fname' not exist."
 exit
}

if { [catch {set fp [open $fname r]} result] } {
 printf "open file '$fname' error."
 exit
}

foreach line [split [read $fp] /n] {
  # Process line
  puts $line
}


close $fp

你可能感兴趣的:(Tcl/Expect)