21.1.4 Types of Tcl Commands
(Ask a Question)This section describes the following types of Tcl commands:
21.1.4.1 Built-in Commands
(Ask a Question)Built-in commands are provided by the Tcl interpreter. They are available in all Tcl applications.
- Tcl provides several commands for manipulating file names, reading and writing file attributes, copying files, deleting files, creating directories, and so on.
- You can execute an external program
using
exec
. Upon execution, the return value is the output (on stdout) from the external program, for example:set tmp [ exec myprog ] puts stdout $tmp
- You can easily create collections of values (lists) and manipulate them in a variety of ways.
- You can create arrays - structured values consisting of name-value pairs with arbitrary string values for the names and values.
- You can manipulate the time and date variables.
- You can write scripts that can wait for certain events to occur, such as an elapsed time or the availability of input data on a network socket.
21.1.4.2 Procedures Created with the proc Command
(Ask a Question)You use the proc
command to declare a procedure. You can then use
the name of the procedure as a Tcl command.
The following sample script consists of a single command named proc
.
The proc
command takes three arguments:
- The name of a procedure (
myproc
) - A list of argument names (
arg1 arg2
) - The body of the procedure, which is a Tcl
script
proc myproc { arg1 arg2 } { # procedure body } myproc a b