[TOC]
## 輸出到終端,盡量使用雙引號
```
puts "hello,world"
```
## 多行注釋
```
if 0 {
這是第一次使用tcl
}
puts "上面是多行注釋"
```
## 查看版本號
```
puts "version:$tcl_version"
```
## 環境路徑
```
puts "環境路徑$env(PATH)"
```
## tcl啟動文件
```
puts "啟動文件:$tcl_rcFileName"
```
## 數學計算 Tcl默認精度為12位 可以使用tcl_precision特殊變量改變精度
```
puts [expr 1 + 1 + 5]
```
## 變量,字符串(list)
```
set var 24
set str {mstring a b c}
puts "$var:[lindex $str 1]"
```
## 關聯數組(如同哈希表)
```
set marks(english) 80
puts english:$marks(english)
set marks(mathematics) 90
puts mathematics:$marks(mathematics)
```
## 動態類型,數據類型自動轉換
```
if 0 {
TCL是一種動態類型語言。
變量的值可以在需要時被動態地轉換為所需的類型。
例如,一個數字5,其被存儲為字符串將做的算術運算時被轉換為數字。
}
set variableA "10"
puts $variableA
set sum [expr $variableA +20];
puts $sum
```
## tcl的運算符和c語言基本一樣 只有一些細微差別
```
set a 21
set b 10
set c [expr $a + $b]
puts "Line 1 - Value of c is $c\n"
set c [expr $a - $b]
puts "Line 2 - Value of c is $c\n"
set c [expr $a * $b]
puts "Line 3 - Value of c is $c\n"
set c [expr $a / $b]
puts "Line 4 - Value of c is $c\n"
set c [expr $a % $b]
puts "Line 5 - Value of c is $c\n"
```
### 注意else的位置和條件是用大括號括起來的
```
if {10 > 5} {
puts "a大于c"
} else {
puts "a不大于c"
}
if {!10 || 5} {
puts "true"
} else {
puts "false"
}
set d [expr 2>3?2 : 3]
puts $d
set a 100
#check the boolean condition
if { $a == 10 } {
# if condition is true then print the following
puts "Value of a is 10"
} elseif { $a == 20 } {
# if else if condition is true
puts "Value of a is 20"
} elseif { $a == 30 } {
# if else if condition is true
puts "Value of a is 30"
} else {
# if none of the conditions is true
puts "None of the values is matching"
}
puts "Exact value of a is: $a"
```
## case語句 注意空格
```
set grade 2
switch $grade {
1 {
puts "grade=1"
}
2 {
puts "grade=2"
}
3 {
puts "grade=3"
}
default {
puts "grade=10"
}
}
```
## for 循環
```
for { set a 10} {$a < 20} {incr a} {
puts "value of a: $a"
}
```
## 數組
```
set languages(0) Tcl
set languages(1) "C Language"
puts $languages(0)
puts $languages(1)
puts [array size languages]
```
## 函數
```
proc helloWorld {} {
puts "Hello, World!"
}
helloWorld
proc add {a b} {
return [expr $a+$b]
}
puts [add 10 30]
```
## 文件操作
```
set myfile [open "t.txt" w+]
puts $myfile "我好細化你"
puts $myfile "超級大保健"
close $myfile
set fp [open "t.txt" r]
set file_data [read $fp]
puts $file_data
close $fp
```
[基礎教程](https://www.yiibai.com/tcl/tcl_regular_expressions.html#article-start)
- 第1章 電腦操作篇
- 1.1 電腦高清壁紙下載地址
- 1.2 音樂外鏈在線獲取
- 1.3 markdown,js等表格生成神器
- 1.4 在線使用文檔,表格,演示文檔
- 1.5 開發在線工具
- 1.5.1 toolbox
- 1.5.2 菜鳥工具
- 1.6 vs code遠程調試
- 1.7 windows批處理命令
- 1.8 windows安裝cygwin運行linux指令
- 1.9 windows下某些程序運行慢
- 1.10 win下為鼠標右鍵添加新項目
- 1.11 win上自己常用的開發軟件
- 1.12 win下vscode配置
- 第2章 Electron 用前端技術開發跨平臺桌面應用
- 2.1 介紹
- 2.2 入門鏈接地址
- 2.3 cnpm使用
- 第3章 Git使用
- 3.1 介紹
- 3.2 同步GitHub的基本使用方法
- 3.3 同步Gitee的基本使用方法
- 3.4 獲取當前git分支
- 3.5 LF和CRLF換行的轉換
- 第4章 HTML,CSS,JS
- 4.1 HTML速查列表
- 第5章 python使用
- 5.1 文件操作
- 5.2 一句話建立服務器
- 第6章 我的女友叫Linux
- 6.1 使用shell寫俄羅斯方塊
- 6.2 那些有趣的shell
- 6.2.1 40個有趣的LInux命令行
- 6.2.2 命令行下的網易云搜索播放器
- 6.2.3 從網上獲取一條語句并顯示
- 6.3 在linux上寫匯編
- 6.4 在linux終端連接另一臺linux
- 6.5 makefile文件的編寫
- 6.6 deepin掛載遠程文件夾到本地文件夾
- 6.7 本地lnux和遠程linux進行文件拷貝
- 6.8 超好用的linux下的ssh管理工具(electerm)
- 6.9 那些不重要的技巧
- 6.10 linux文件加密
- 6.11 論文畫圖軟件gnuplot
- 6.12 自定義mrun命令用于執行當前路徑下的run文件
- 6.13 fish shell后臺運行程序
- 第7章 在線工具收集
- 7.1 各種編程語言的在線編輯運行
- 7.2 html js 在線嘗試
- 第8章 搭建自己的私有云盤
- 第9章 linux下的一些軟件
- 9.1 remarkable--markdown文件輕量編輯器
- 9.2 gnuplot畫圖軟件
- 9.3 Graphviz繪圖(流程圖,狀態圖)
- 第10章 TCL腳本編程
- 10.1 基礎教程
- 10.2 在tcl腳本文件其他tcl腳本文件運行
- 10.3 在tcl腳本文件中調用bash/fish
- 10.4 TCL培訓教程
- 10.5 tcl腳本參數傳遞
- 第11章 看云的使用
- 11.1 markdown添加公式
- 11.2 看云在linux本地編輯腳本
- 第12章 Go語言在linux下的使用
- 12.1 簡介
- 12.2 調用自己的包
- 12.3 Go語言學習的資料
- 12.4 golang使用flag完成命令行解析
- 12.5 Golang文件操作大全
- 12.5.1 創建空文件
- 12.5.2 Truncate文件
- 12.5.3 得到文件信息
- 12.5.4 重命名和移動
- 12.5.5 刪除文件
- 12.5.6 打開和關閉文件
- 12.5.7 檢查文件是否存在
- 12.5.8 檢查讀寫權限
- 12.5.9 改變權限、擁有者、時間戳
- 12.5.10 硬鏈接和軟鏈接
- 12.5.11 復制文件
- 12.5.12 跳轉到文件指定位置(Seek)
- 12.5.13 寫文件
- 12.5.14 快寫文件
- 12.5.15 使用緩存寫
- 12.5.16 讀取最多N個字節
- 12.5.17 文件追加內容
- 12.6 操作CSV文件
- 第13章 搜集資源的一些方法
- 13.1 電子書_電子課本
- 第14章 EndNote的使用
- 14.1 安裝
- 14.2 文件檢索