Combine Tcl and Shell Script into One File

风行水上 @ 2014-07-03 01:35:25
标签:

    场景:

    需要在执行Tcl程序通过Shell程序设置环境。

    • 不可以通过Tcl的exec命令达到目的。因为子进程不能改变父进程。
    • 不可以通过简单的set ::env(NAME) VALUE来实现。因为设置过程还挺“复杂”。
    • 不希望在Tcl程序之外在加一个Shell的wrapper程序。两个程序文件看起来不舒服。

    可以用下面的方法

    #!/bin/bash
    #!/path/to/tclsh8.5
    # environment setting use shell \
    source /some/common/settings.sh
    # restart use tclsh \
    exec /path/to/tclsh8.5 "$0" "$@"
    
    # Below is Tcl Code
    
    puts "*** PONE Tcl - Infinite Running ***\n"
    
    

    关键点是利用Tcl中通过行尾的反斜线实现的跨行注释,在Shell程序中确只有第一行算是注释。

    参见:Tcl中的注释

    标签:

      分享到:
      comments powered by Disqus

      28/32ms