variable − create and initialize a namespace variable


variable name

variable ?name value...? ___________________________


This command is normally used within a namespace eval command to create one or more variables within a namespace. Each variable name is initialized with value. The value for the last variable is optional.

If a variable name does not exist, it is created. In this case, if value is specified, it is assigned to the newly created variable. If no value is specified, the new variable is left undefined. If the variable already exists, it is set to value if value is specified or left unchanged if no value is given. Normally, name is unqualified (does not include the names of any containing namespaces), and the variable is created in the current namespace. If name includes any namespace qualifiers, the variable is created in the specified namespace. If the variable is not defined, it will be visible to the namespace which command, but not to the info exists command.

If the variable command is executed inside a Tcl procedure, it creates local variables linked to the corresponding namespace variables (and therefore these variables are listed by info vars.) In this way the variable command resembles the global command, although the global command only links to variables in the global namespace. If any values are given, they are used to modify the values of the associated namespace variables. If a namespace variable does not exist, it is created and optionally initialized.

A name argument cannot reference an element within an array. Instead, name should reference the entire array, and the initialization value should be left off. After the variable has been declared, elements within the array can be set using ordinary set or array commands.


Create a variable in a namespace:

namespace eval foo {
bar 12345

Create an array in a namespace:

namespace eval someNS {
array set someAry {
someName someValue
otherName otherValue

Access variables in namespaces from a procedure:

namespace eval foo {
proc spong {} {
# Variable in this namespace
puts "bar is $bar"

# Variable in another namespace
parray someAry


global(n), namespace.conf(5), upvar(n)


global, namespace, procedure, variable

More Linux Commands

XGrabPointer(3) - grab the pointer - Linux manual page......
The XGrabPointer function actively grabs control of the pointer and returns GrabSuccess if the grab was successful. Further pointer events are reported only to

gnutls_openpgp_keyring_deinit(3) - API function (Man Page)
This function will deinitialize a keyring structure. REPORTING BUGS Report bugs to <>. GnuTLS home page: G

perlfunc(1) - Perl builtin functions - Linux manual page....
The functions in this section can serve as terms in an expression. They fall into two major categories: list operators and named unary operators. These differ i

Tcl_UniCharIsControl(3) - routines for classification of Tcl
All of the routines described examine Tcl_UniChars and return a boolean value. A non-zero return value means that the character does belong to the character cla

atan2(3) - arc tangent function of two variables (Man Page)
The atan2() function calculates the principal value of the arc tangent of y/x, using the signs of the two arguments to determine the quadrant of the result. RET

mvin_wch(3ncurses) - extract a complex character and renditi
These functions extract the complex character and rendition from the current position in the named window into the cchar_t object referenced by wcval. RETURN VA

lavpipe(1) - creates raw YUV streams from pipe list scripts
lavpipe reads a script file called pipe list that is of a similar structure as the edit lists that can be fed into lav2yuv. For info about the pipe list format

Tcl_SetDoubleObj(3) - manipulate Tcl objects as floating-poi
These procedures are used to create, modify, and read Tcl objects that hold double-precision floating-point values. Tcl_NewDoubleObj creates and returns a new T

SDL_SetCursor(3) - Set the currently active mouse cursor....
Sets the currently active cursor to the specified one. If the cursor is currently visible, the change will be immediately represented on the display. SEE ALSO S

joe(1) - Joe's Own Editor (Commands - Linux manual page)....
JOE is a powerful ASCII-text screen editor. It has a mode-less user interface which is similar to many user-friendly PC editors. Users of Micro-Pros WordStar or

fblocked(n) - Test whether the last input operation exhauste
The fblocked command returns 1 if the most recent input operation on channelId returned less information than requested because all available input was exhauste

xml_pp(1) xml prettyprinter (Commands - Linux man page).....
XML pretty printer using XML::Twig OPTIONS -i[<extension>] edits the file(s) in place, if an extension is provided (no space between -i and the extension) then

We can't live, work or learn in freedom unless the software we use is free.