📜  Tcl-特殊变量

📅  最后修改于: 2020-10-16 06:23:21             🧑  作者: Mango


在Tcl中,我们将某些变量归类为特殊变量,并且它们具有预定义的用法/功能。特殊变量列表如下。

Sr.No. Special Variable & Description
1

argc

Refers to a number of command-line arguments.

2

argv

Refers to the list containing the command-line arguments.

3

argv0

Refers to the file name of the file being interpreted or the name by which we invoke the script.

4

env

Used for representing the array of elements that are environmental variables.

5

errorCode

Provides the error code for last Tcl error.

6

errorInfo

Provides the stack trace for last Tcl error.

7

tcl_interactive

Used to switch between interactive and non-interactive modes by setting this to 1 and 0 respectively.

8

tcl_library

Used for setting the location of standard Tcl libraries.

9

tcl_pkgPath

Provides the list of directories where packages are generally installed.

10

tcl_patchLevel

Refers to the current patch level of the Tcl interpreter.

11

tcl_platform

Used for representing the array of elements with objects including byteOrder, machine, osVersion, platform, and os.

12

tcl_precision

Refers to the precision i.e. number of digits to retain when converting to floating-point numbers to strings. The default value is 12.

13

tcl_prompt1

Refers to the primary prompt.

14

tcl_prompt2

Refers to the secondary prompt with invalid commands.

15

tcl_rcFileName

Provides the user specific startup file.

16

tcl_traceCompile

Used for controlling the tracing of bytecode compilation. Use 0 for no output, 1 for summary, and 2 for detailed.

17

tcl_traceExec

Used for controlling the tracing of bytecode execution. Use 0 for no output, 1 for summary, and 2 for detailed.

18

tcl_version

Returns the current version of the Tcl interpreter.

上面的特殊变量对Tcl解释器有特殊的含义。

使用Tcl特殊变量的示例

让我们看一些特殊变量的例子。

TCL版本

#!/usr/bin/tclsh

puts $tcl_version

运行程序时,您将获得类似的输出,如下所示-

8.6

Tcl环境路径

#!/usr/bin/tclsh

puts $env(PATH)

运行程序时,您将获得类似的输出,如下所示-

/home/cg/root/GNUstep/Tools:/usr/GNUstep/Local/Tools:/usr/GNUstep/
System/Tools:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/webmaster/.local/bin:/
home/webmaster/bin:/usr/local/scriba/bin:/usr/local/smlnj/
bin:/usr/local/bin/std:/usr/local/bin/extra:/usr/local/fantom/bin:/usr/
local/dart/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/opt/mono/
bin:/opt/mono/lib/mono/4.5:/usr/local/bin:.:/usr/libexec/sdcc:/usr/local/
icon-v950/bin:/usr/local/mozart/bin:/opt/Pawn/bin:/opt/jdk1.7.0_75/bin:/
opt/jdk1.7.0_75/jre/bin:/opt/pash/Source/PashConsole/bin/Debug/

Tcl包路径

#!/usr/bin/tclsh

puts $tcl_pkgPath

运行程序时,您将获得类似的输出,如下所示-

/usr/lib64/tcl8.6 /usr/share/tcl8.6 /usr/lib64/tk8.6 /usr/share/tk8.6

Tcl库

#!/usr/bin/tclsh

puts $tcl_library

运行程序时,您将获得类似的输出,如下所示-

/usr/share/tcl8.6

Tcl补丁程序级别

#!/usr/bin/tclsh

puts $tcl_patchLevel

运行程序时,您将获得类似的输出,如下所示-

8.6.6

Tcl精度

#!/usr/bin/tclsh

puts $tcl_precision

运行程序时,您将获得类似的输出,如下所示-

0

Tcl启动文件

#!/usr/bin/tclsh

puts $tcl_rcFileName

运行程序时,您将获得类似的输出,如下所示-

~/.tclshrc