博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tcl使用笔记
阅读量:6253 次
发布时间:2019-06-22

本文共 2846 字,大约阅读时间需要 9 分钟。

tcl语法网站:http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm

1)拷贝文件

 set PRJ_HDL_DIR "../prj/hdl"

foreach filename [glob "../tsbs/smii_mtip/rtl/include/{*.verilog,*.v}"] {
    file copy $filename $PRJ_HDL_DIR
}

2)如何获取当前脚本文件的名称?

由于有时需要获得当前运行脚本的名称,可以参考 如下

http://blog.csdn.net/gllg1314/article/details/7695746

http://wiki.tcl.tk/1384

http://stackoverflow.com/questions/23285360/how-to-get-path-of-current-script

 While a script is being evaluated (but not necessarily while its procedures are being called) the current script name (strictly, whatever was passed to source or the C API equivalent, Tcl_EvalFile() and related) is the result of info script; it's highly advisable to normalise that to an absolute pathname so that any calls to cd don't change the interpretation.

Scripts that need the information tend to put something like this inside themselves:
# This is a *good* use of [variable]…
variable myLocation [file normalize [info script]]
They can then retrieve the value (or things derived from it) easily:
proc getResourceDirectory {} {
    variable myLocation
    return [file dirname $myLocation]

依据参考得到的代码:

set print echo

$print "----------------------------------------"
$print "  rs                                 - Re-Source startup file "
$print "  comp_afu_textswap       - Compile memcopy example "
$print "  sim                               - Start vsim"
$print "----------------------------------------"
variable My_File [file normalize [info script]]
# the above line can't be put in the rs{} procedure.
proc rs {} {
    variable My_File
    set filename [file tail $My_File]
    echo "current file is $filename"
    source $filename
}
 

需要指出的是

a.variable My_File [file normalize [info script]] 这句话不能放在rs procedure中,否则得到空字符

b.rs函数中的variable My_File就是全局变量的My_File的值

 

===========================

1)

#set PRJ_HDL_DIR {$PRJ_ROOT_DIR}/prj/hdl    则[ Line 3: extra characters after close-brace ]
#set PRJ_HDL_DIR "{$PRJ_ROOT_DIR}/prj/hdl"  则{}会被当成字符,当成了 {..}/prj/hdl"
#set PRJ_HDL_DIR ${PRJ_ROOT_DIR}/prj/hdl  correct!!!
#set PRJ_HDL_DIR "${PRJ_ROOT_DIR}/prj/hdl"  correct!!
2)
  {}里面不能有注释?
foreach pathname {1 2 3} ${
#    foreach filename [glob "../tsbs/smii_mtip/rtl/include/{*.verilog,*.v}"] {
    puts "pathname = $pathname"
#    foreach filename [glob "${pathname}{*.verilog,*.v}"] {
#    file copy $filename $PRJ_HDL_DIR
#    }
}  
Error: Failure when executing Tcl script. [ Line 10: can't read "
# foreach filename [glob "../tsbs/smii_mtip/rtl/include/{*.verilog,*.v": no such variable ]
Error: The Execute Script command failed.
3)
pathname = ${PRJ_ROOT_DIR}/tsbs/smii_mtip/rtl/include/
pathname = $PRJ_ROOT_DIR/tsbs/sgmii_mtip/rtl/include/
The Execute Script command succeeded.
{} 中间不能替换,但是foreach需要列表,其实是不需要,如下就能正确工作
set INCLUDE_PATH_ARRAY  "${PRJ_ROOT_DIR}/tsbs/smii_mtip/rtl/include/ $PRJ_ROOT_DIR/tsbs/sgmii_mtip/rtl/include/"
foreach pathname $INCLUDE_PATH_ARRAY {
    puts "pathname = $pathname"
}

 

转载于:https://www.cnblogs.com/e-shannon/p/5820993.html

你可能感兴趣的文章
[C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密
查看>>
javascript 自定义错误处理
查看>>
POJ 3278 Catch That Cow(BFS,板子题)
查看>>
Ubuntu下U盘只读文件系统,图标上锁,提示无法修改
查看>>
TCP/IP具体解释学习笔记--TCP的超时与重传
查看>>
C#设计模式之十一享元模式(Flyweight Pattern)【结构型】
查看>>
基于zookeeper简单实现分布式锁
查看>>
Makefile:160: recipe for target 'all' failed (Ubuntu 16.06 + Opencv3.2)解决办法
查看>>
a WebSite for MapXtreme2005 Crack
查看>>
几种函数调用方式
查看>>
【MySQL】MySQL 常用语法之锁表与解锁表
查看>>
【142】阿蛮歌霸使用技巧
查看>>
HTTP 请求报文 响应报文
查看>>
[转载] 程序员必看:请不要做浮躁的人 24法则
查看>>
JavaWeb_JavaEE_命名规则
查看>>
HDU 4010 Query on The Trees
查看>>
[PAL规范]SAP HANA PAL 数据处理四分位间距检测Inter-quartile Range Test编程规范IQRTEST...
查看>>
[HDU 1317]XYZZY[SPFA变形][最长路]
查看>>
Skip list--reference wiki
查看>>
解决Asp输出乱码问题
查看>>