blue1025的个人空间 https://blog.eetop.cn/mj8051 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

Tcl编程简介(四)

已有 1980 次阅读| 2008-8-26 11:07 |个人分类:linux

Error命令


error message
error message info
error message info code




  返回一个错误,引起解释器停止运行。info用于初始化全局变量errorInfo。code被付给errorCode。


eval arg ...


  将所有的参数连起来作为命令语句来执行。


exec arg ...


  仿佛是在shell下执行一条命令。



exec ls --color
exec cat /etc/passwd > /tmp/a


exit
exit returnCode



  中断执行。


expr arg


  处理表达式。



set a [expr 1+1]
//a=2


file subcommand name



  一组用于文件处理的命令。



file subcommand name arg ...
file atime name



  返回文件的最近存取时间。


file dirname name


  返回name所描述的文件名的目录部分。


file executable name


  返回文件是否可被执行。


file exists name


  返回1 表示文件存在,0 表示文件不存在。


file extension name


  返回文件的扩展名。


file isdirectory name


  判断是否为目录。


file isfile name


  判断是否为文件。


file lstat name varName


  以数组形式返回。执行lstat系统函数。存储在varName。


file mtime name


  文件的最近修改时间。


file owned name


  判断文件是否属于你。


file readable name


  判断文件是否可读。


file readlink name


  都出符号连接的真正的文件名。


file rootname name


  返回不包括最后一个点的字符串。


file size name


  返回文件的大小。


file stat name varName


  调用stat内和调用,以数组形式存在varName中。


file tail name


  返回最后一个斜线以后的部分。


file type name


  返回文件类型file, directory, characterSpecial, blockSpecial, fifo, link, 或socket。


file writable name


  判断文件是否可写。


flush fileId


  立即处理由fileId描述的文件缓冲区。


for start test next body


  for循环。同C总的一样。



for {set i 1} {$i < 10} {incr i} {puts $i}
foreach varname list body



  类似于C Shell总的foreach或bash中的for..in...



format formatString
format formatString arg ...



  格式化输出,类似于C中的sprintf。



set a [format "%s %d" hello 100]
//a="hello 100"


gets fileId
gets fileId varName



  从文件中读出一行。



set f [open /etc/passwd r]
gets $f


glob filename ...
glob -nocomplain filename ...



  使用C Shell风格的文件名通配规则,对filename进行扩展。



ls /tmp
a b c


tclsh>glob /tmp/*
a b c



  当加上参数 -nocomplain 时,如文件列表为空则发生一个错误。


global varname ...


定义全局变量。



if test trueBody
if test trueBody falseBody
if test then trueBody
if test then trueBody else falseBody



  条件判断,是在没什么说的。



incr varName
incr varName increment



  如果没有incremnet,将varName加一,反之将varName加上increment。



set i 10
incr i
//i=11
incr i 10
//i=21
info subcommand
info subcommand arg ...



  取得当前的Tcl解释器的状态信息。


info args procname


  返回由procname指定的命令(你自己创建的)的参数列表。


  如:



proc ff { a b c } {puts haha}
info args ff
//return "a b c" 


info body procname



  返回由procname指定的命令(你自己创建的)的函数体。


  如:



proc ff { a b c } {puts haha}
info body ff
//return "puts haha" 
info cmdcount



  返回当前的解释器已经执行的命令的个数。



info commands
info commands pattern



  如果不给出模式,返回所有的命令的列表,内建和自建的。


  模式是用C Shell匹配风格写成的。



info complete command



  检查名是否完全,有无错误。


info default procname arg varname


  procname的参数arg,是否有缺省值。


info exists varName


  判断是否存在该变量。



info globals
info globals pattern



  返回全局变量的列表,模式同样是用C Shell风格写成的。


info hostname


  返回主机名。



info level
info level number



  如果不给参数number则返回当前的在栈中的绝对位置,参见uplevel中的描述。如加了参数number,则返回一个列表包含了在该level上的命令名和参数。


info library


  返回标准的Tcl脚本的可的路径。实际上是存在变量tcl_library中。



info locals
info locals pattern



  返回locale列表。



info procs
info procs pattern



  返回所有的过程的列表。


info script.


  返回最里面的脚本(用 source 来执行)的文件名。


info tclversion


  返回Tcl的版本号。



info vars
info vars pattern



  返回当前可见的变量名的列表。


  下面是一些用于列表的命令,范围可以是end。



join list
join list joinString



  将列表的内容连成一个字符串。



lappend varName value ...



  将value加入列表varName中。


lindex list index


  将list视为一个列表,返回其中第index个。列表中的第一个元素下标是0。



lindex "000 111 222" 1
111
linsert list index element ...



  在列表中的index前插入element。


list arg ...


  将所有的参数发在一起产生一个列表。



list friday [exec ls] [exec cat /etc/passwd]
llength list



  返回列表中元素的个数。



set l [list sdfj sdfjhsdf sdkfj]
llength $l
//return 3


lrange list first last



  返回列表中从frist到last之间的所有元素。



set l [list 000 111 222 333 444 555]
lrange $l 3 end
//return 333 444 555


lreplace list first last
lreplace list first last element ...



  替换列表中的从first到last的元素,用element。



set l [list 000 111 222 333 444 555]
lreplace $l 1 2 dklfj sdfsdf dsfjh jdsf
000 dklfj sdfsdf dsfjh jdsf 333 444 555


lsearch -mode list pattern



  在列表中搜索pattern,成功返回序号,找不到返回-1。



-mode : -exact 精确
-glob shell的通配符
-regexp 正则表达式


lsearch "111 222 333 444" 111
//return 0
lsearch "111 222 333 444" uwe
//return 1


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 13

    粉丝
  • 16

    好友
  • 15

    获赞
  • 23

    评论
  • 2824

    访问数
关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-20 23:45 , Processed in 0.027789 second(s), 14 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部