以下是我的$ file_path
的内容if **{**[info exists ABC] && $ABC == "xyz"} **{**
# constraints
# TODO:
echo "do something"
}
我希望打印此文件的内容,因为它在dofile.tcl中。但不知何故,下面的代码开头和结尾打开括号" {"以粗体显示的高位被忽略。
结果:
if [info exists ABC] && $ABC == "xyz"} **#Notice the missing { both in begin and end**
# constraints
# TODO:
echo "do something"
}
代码:
set fp [open "$file_path" r]
set file_data [read $fp]
close $fp
echo "D1 : file data is $file_data" >> abc.log
set data [split $file_data "\n"]
foreach line $data {
echo "D2: Line is $line" >> abc.log
if { ! [regexp {^\#} $line] } {
echo "$line" >> dofile.tcl
}
}
D1使用"打印整个数据。{"根据需要,D2省略" {"
答案 0 :(得分:0)
尝试使用puts而不是echo,如:
set lf [open "abc.log" w]
set tf [open "dofile.tcl" w]
set fp [open "$file_path" r]
set file_data [read $fp]
close $fp
puts $lf "D1 : file data is $file_data"
set data [split $file_data "\n"]
foreach line $data {
puts $lf "D2: Line is $line"
if { ! [regexp {^\#} $line] } {
puts $tf "$line"
}
}
close $lf
close $tf
我的输出如下:
if **{**[info exists ABC] && $ABC == "xyz"} **{**
# constraints
# TODO:
echo "do something"
}