
where get elements returns the operands to operate on as a Tcl list and modify elements operates on
those operands. Tcl also helps extensibility by being interpreted. This means that you can add code on the
fly to your program and modify the behavior of the code shipped with the system. Tcl also has associative
arrays built in; these are the regular Tcl array variables. Internally, they are implemented as hash tables
so lookup on them is very speedy. Multi-dimensional arrays can be simulated in Tcl by using concatenated
indices in regular arrays.
1.2.1 An Introduction to Tcl
Safe interpreters are simply regular interpreters with certain “unsafe” calls removed; that is, they are inter-
preters where some unsafe code has already been “dejected.” All Tcl interpreters in Amanda Portal are of
the “safe” variety, and as such, they have only the following standard Tcl commands: append,array,break,
case,catch,concat,continue,error,eval,expr,for,foreach,format,gets,global,if,incr,info,
interp,join,lappend,lindex,linsert,list,llength,lower,lrange,lreplace,lsearch,lsort,proc,
regexp,regsub,return,scan,set,split,source,string,switch,time,trace,unset,uplevel,upvar,
and while.
This subsection gives a brief description of each of these commands. Those who are already familiar with
Tcl should skip ahead to the next section. There are many books available which cover the Tcl language,
including Tcl and the Tk Toolkit, by Tcl’s author, John Ousterhout, and Tcl For Dummies, in the famous
“Dummies” series. While those books should be consulted for in-depth examples, they also cover many more
features of Tcl, plus the Tk graphical extensions, which are not used in Amanda Portal.
Tcl Variables
Programming languages contain two fundamental elements: variables and procedures. Object-oriented lan-
guages combine these two features into objects (naturally). Variables in Tcl have three attributes:
name The variable’s name allows access to its contents.
scope The scope of a variable determines how long it will live. When it goes out of scope, a variable is
automatically destroyed.
value Finally, each variable has a value.
In many programming languages, variables have a fourth attribute, a type, which determines the kind of
data that the variable can have as its value, the size of the date (range of values, length of a string, etc.). In
these languages, variables are declared, and a variable can exist without having a defined value.
Tcl’s variables, like those of Amanda@Work.Group, do not have a specific type. Internally, they are all
represented as strings and are converted on-the-fly as needed to other types (floating point, integer) when
necessary. This feature makes Tcl programming easier. A variable springs into existence the first time it is
used. This also means that it’s impossible to have a variable which does not have any value.
To create a variable in Tcl, you use the set command, like this:
set variable value
For example, to set the variable myname to Tim, you would simply type
7