linux运行tcl脚本语言,Tool Command Language (Tcl)初体验
Tcl只有一种语法: command arg arg ....
这种设计真的是非常好,简洁,快速!
它和很多程序设计语言不一样,它没有关键词!譬如if, switch在Tcl中也是命令。
初次体验Tcl的感觉是:利用Tcl来构建一些东西的时候,只做两件事情:一,调用命令;二,直接给参数或者用替换的方法给参数。 仅有的一种语法在有了“可替换“这个特性后,果然强大了很多!可见,好的设计,真的是至简的设计。你无法再用更少的东西来达到相同的目的了。
Tcl也是支持结构化的,比如c中的function,可以对应为Tcl中的proc(procedure的简称)。
proc procName args... {
main body
}
这样就相当于定义了一个procedure。其实,它还是个命令,这个命令做的事情的,当procName被调用时,执行mainbody.
以下给出我初步试验的脚本和结果:
#test tcl built-in commands
puts "======================start=========================="
#print "running" after 5 seconds
puts "waiting for 1 second ..."
after 1000
puts "running ..."
#append var(="Hello") with " " and "World!"
set var {}
append var "Hello" " " "World!"
puts ${var}
#test command 'for', 'if' and 'incr'
#output the odd number between [1:10]
for {set i 1} {$i <= 10} {incr i} {
if {$i%2 != 0} {puts $i}
}
#command substitution
set var [expr 1+2+3]
puts $var
#file
puts [file attributes tmp.tcl]
puts [file atime tmp.tcl]
puts [file channels *err]
puts [file dirname ~]
puts [file dirname ~/Desktop]
#file copy tmp.tcl commandtest.tcl
set flag [file executable commandtest.tcl]
if {$flag == 1} {
puts "commandtest.tcl is executable"
}
if {$flag == 0} {
puts "commandtest.tcl is not executable"
}
file mkdir testdir1 testdir2 testdir3
puts [file normalize commandtest.tcl]
puts [file separator]
#test 'proc' and 'cd'
proc mypwd args {
return [file normalize ./]
}
puts [mypwd]
set current_dir [file normalize ./]
cd /home/chenqi/Desktop
puts [mypwd]
cd ${current_dir}
puts [mypwd]
#test pwd
puts [pwd]
#test 'file stat', 'array' and 'foreach'
file stat commandtest.tcl var_stat_array
foreach {field value} [array get var_stat_array] {
puts "field: $field; value: $value"
}
puts $::tcl_platform(platform)
#test 'switch'
switch $::tcl_platform(platform) {
unix {
puts "the platform is unix"
}
windows {
puts "the platform is windows"
}
}
#test 'exec'
puts "executing 'uname -r' command"
puts [exec uname -r]
#test time
puts [time {
puts [exec find /home/chenqi/MyPro/CFiles/ -name *.c]
}]
puts "===================end================================="
======================start==========================
waiting for 1 second ...
running ...
Hello World!
1
3
5
7
9
6
-group root -owner root -permissions 00644
1336199519
stderr
/
~
commandtest.tcl is executable
/home/chenqi/MyPro/ShellScript/tcl/commandtest.tcl
/
/home/chenqi/MyPro/ShellScript/tcl
/home/chenqi/Desktop
/home/chenqi/MyPro/ShellScript/tcl
/home/chenqi/MyPro/ShellScript/tcl
field: mtime; value: 1336203195
field: atime; value: 1336203234
field: gid; value: 0
field: nlink; value: 1
field: mode; value: 33261
field: type; value: file
field: ctime; value: 1336203195
field: uid; value: 0
field: ino; value: 2360375
field: size; value: 1724
field: dev; value: 2056
unix
the platform is unix
executing 'uname -r' command
2.6.32-21-generic
/home/chenqi/MyPro/CFiles/temp/bufsiz.c
/home/chenqi/MyPro/CFiles/Chapter-1/Hello.c
/home/chenqi/MyPro/CFiles/POSIX_Threads/autobakup.c
/home/chenqi/MyPro/CFiles/POSIX_Threads/thread1.c
/home/chenqi/MyPro/CFiles/virtual_process/virt_proc.c
/home/chenqi/MyPro/CFiles/virtual_process/test.c
/home/chenqi/MyPro/CFiles/virtual_process/hash.c
/home/chenqi/MyPro/CFiles/virtual_process/pid.c
/home/chenqi/MyPro/CFiles/IPC/semaphores/cfunc.c
/home/chenqi/MyPro/CFiles/IPC/pipes/named_pipes/client.c
/home/chenqi/MyPro/CFiles/IPC/pipes/named_pipes/server.c
/home/chenqi/MyPro/CFiles/IPC/pipes/named_pipes/tmp/procB.c
/home/chenqi/MyPro/CFiles/IPC/pipes/named_pipes/tmp/procA.c
/home/chenqi/MyPro/CFiles/IPC/pipes/named_pipes/server_with_queue.c
/home/chenqi/MyPro/CFiles/IPC/pipes/pipes_as_stdio/pipe_as_stdout.c
/home/chenqi/MyPro/CFiles/IPC/pipes/pipes_as_stdio/pipe_as_stdin.c
/home/chenqi/MyPro/CFiles/IPC/pipes/unnamed_pipes/procB.c
/home/chenqi/MyPro/CFiles/IPC/pipes/unnamed_pipes/procA.c
/home/chenqi/MyPro/CFiles/IPC/signals/test.c
/home/chenqi/MyPro/CFiles/IPC/signals/getpidbyname.c
/home/chenqi/MyPro/CFiles/IPC/signals/test2.c
/home/chenqi/MyPro/CFiles/programming-pearls/chapter1/qsort.c
/home/chenqi/MyPro/CFiles/programming-pearls/chapter1/mergesort.c
/home/chenqi/MyPro/CFiles/programming-pearls/chapter1/tmp/test.c
/home/chenqi/MyPro/CFiles/programming-pearls/chapter1/bitmap_sort.c
/home/chenqi/MyPro/CFiles/programming-pearls/chapter1/generate_random.c
4776 microseconds per iteration
===================end=================================
linux运行tcl脚本语言,Tool Command Language (Tcl)初体验相关推荐
- linux 运行lua脚本语言,你知道在linux下搭建lua脚本语言的编程环境?
描述 lua是脚本语言的一种,具体的该脚本的介绍可百度,本文介绍Linux系统下搭建lua编程环境的步骤,以及在搭建过程中碰到的种种问题. 一.下载获取lua源码 地址http://www.lua.o ...
- TCL(Tool Command Language)
TCL(Tool Command Language)是一种解释执行的脚本语言.具有良好的跨平台特性和**可扩展性,TCL本身是用C语言实现的,可以很方便的通过C语言进行扩充,增加新的**命令, ...
- TCL脚本语言基础介绍
Tcl简介(一):Tcl 语法 Tcl 语法 Tcl是一种很通用的脚本语言,它几乎在所有的平台上都可以释运行,其强大的功能和简单精妙的语法会使你感到由衷的喜悦,这片文章对 Tcl有很好的描述和说明.如 ...
- EDA实验课课程笔记(三)——TCL脚本语言的学习1
本文参考资料为<Tcl语言教程>,感谢作者的分享,这里仅仅作为简单常用语法的入门,若有需要后期对本文进行添加补充. EDA实验课课程笔记(三)--TCL脚本语言的学习 前言(TCL综述) ...
- TCL脚本语言详解(1)
语言简介 TCL是一种很通用的脚本语言,功能强大.最早称为"工具命令语言""Tool Command Language",但是目前已经不是这个含义,不过我们仍然 ...
- tcl计算机语言,Vivado之TCL脚本语言基本语法介绍
TCL脚本语言 Tcl(Tool Command Language)是一种很通用的脚本语言,它几乎在所有的平台上都可以解释运行,而且VIVADO也提供了TCL命令行.最近发现TCL脚本貌似比GUI下操 ...
- TCL脚本语言光速入门教程,一篇就够了(超全查表)
目录 引子:初见TCL 基本命令 置换命令 普通置换 变量置换 命令置换 反斜杠置换 其他置换 脚步命令 eval命令 source命令 语言命令 简单变量 数组变量 重构变量及其操作 补充概念 全局 ...
- EDA实验课课程笔记(四)——TCL脚本语言的学习2
EDA实验课课程笔记(四)--TCL脚本语言的学习2 控制流 if 循环命令 while for foreach break和continue命令 switch source 过程(procedure ...
- Vivado中的TCL脚本语言
本文介绍了Tcl在Vivado中的基础应用,希望起到抛砖引玉的作用,指引使用者在短时间内快速掌握相关技巧,更好地发挥Vivado在FPGA设计中的优势. Vivado TCL脚本语言 使用Tcl作为它 ...
最新文章
- mysql right join实例_mysql left join,right join,inner join简单实例
- 在电脑上实现手机app抓包
- Iterator 和 ListIterator 有什么区别?
- obj.toSource()
- HTTP请求返回状态码和提示信息
- Page Ability 之间的跳转概念和应用分享
- P3309-[SDOI2014]向量集【线段树,凸壳】
- Linux 组合命令/命令组合的符号
- olive videoeditor开源跨平台视频编辑器
- SharePoint 2010: 对于开发人员
- Pytorch Tensor.unfold()的简单理解与用法
- 游戏界的扛把子、3D 游戏之父约翰•卡马克的传奇人生
- 01 linux操作系统概述与安装
- Linux下多网卡绑定bonding bond6
- 腾讯视频国际版(Android)电量测试方法研究与总结
- 可视化网络监控软件OpManager获选″IT运维产品之星”
- 在计算机上配置超级终端,电脑中如何添加超级终端?添加超级终端的方法
- SICP练习1.17
- 【大厂面试】面试官看了赞不绝口的Redis笔记
- lock与unlock用法(简单易懂)