in tcl, we classify some of the variables as special variables and they have a predefined usage/functionality. the list of specials variables is listed below.
| 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. |
the above special variables have their special meanings for the tcl interpreter.
examples for using tcl special variables
let's see some examples for special variables.
tcl version
#!/usr/bin/tclsh puts $tcl_version
when you run the program, you will get a similar output as shown below −
8.6
tcl environment path
#!/usr/bin/tclsh puts $env(path)
when you run the program, you will get a similar output as shown below −
/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 package path
#!/usr/bin/tclsh puts $tcl_pkgpath
when you run the program, you will get a similar output as shown below −
/usr/lib64/tcl8.6 /usr/share/tcl8.6 /usr/lib64/tk8.6 /usr/share/tk8.6
tcl library
#!/usr/bin/tclsh puts $tcl_library
when you run the program, you will get a similar output as shown below −
/usr/share/tcl8.6
tcl patch level
#!/usr/bin/tclsh puts $tcl_patchlevel
when you run the program, you will get a similar output as shown below −
8.6.6
tcl precision
#!/usr/bin/tclsh puts $tcl_precision
when you run the program, you will get a similar output as shown below −
0
tcl startup file
#!/usr/bin/tclsh puts $tcl_rcfilename
when you run the program, you will get a similar output as shown below −
~/.tclshrc