首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >圆括号中的变量双引号tcl

圆括号中的变量双引号tcl
EN

Stack Overflow用户
提问于 2017-01-11 05:18:38
回答 1查看 1.3K关注 0票数 0

我正在使用这个脚本,我希望脚本替换我的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"}

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2017-01-11 12:25:00

如果您希望值周围有大括号,您可以这样做。

代码语言:javascript
复制
puts $out [list "GRAPHIC_FILE_1 = \"E:/ge work/hyperview scripting/${name}.rst\""]

或者这个

代码语言:javascript
复制
puts $out "{GRAPHIC_FILE_1 = \"E:/ge work/hyperview scripting/${name}.rst\"}"

两者都打印字符串。

{GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/222.rst"}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41583213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档