我正在使用这个脚本,我希望脚本替换我的session.mvw文件的第二行,所以我询问输入"name“,如果我输入2222作为输入,我希望我的session.mvw文件的第二行是{GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/222.rst"},但是它只给出{GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/${name}.rst"}。
puts "Enter your name: "
#flush stdout set name [gets stdin]
set in [open session.mvw r]
# get the path to the parent directory
set hostDir [file dirname session.mvw]
set tempfile "$hostDir/temp2.txt"
# open/create a temp file
set out [open $tempfile w]
set count 0
while { [eof $in] != 1 } {
gets $in line
#set firstItem [lindex $line 0] incr count
# a match has been found...
if {$count == 2 } {
puts $out {GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/${name}.rst"}
} elseif {$count == 3} {
puts $out {GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/${name}.rst"}
} else {
puts $out $line
}
}
close $in
close $out
close $hostDir
# over-write the existing file
#file rename -force $tempfile session_file.mvw发布于 2017-01-11 12:25:00
如果您希望值周围有大括号,您可以这样做。
puts $out [list "GRAPHIC_FILE_1 = \"E:/ge work/hyperview scripting/${name}.rst\""]或者这个
puts $out "{GRAPHIC_FILE_1 = \"E:/ge work/hyperview scripting/${name}.rst\"}"两者都打印字符串。
{GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/222.rst"}
https://stackoverflow.com/questions/41583213
复制相似问题