lassign - Assign list elements to variables
lassign list ?varName ...?
lassign(1t) Tcl Built-In Commands lassign(1t)
______________________________________________________________________________
NAME
lassign - Assign list elements to variables
SYNOPSIS
lassign list ?varName ...?
______________________________________________________________________________
DESCRIPTION
This command treats the value list as a list and assigns successive
elements from that list to the variables given by the varName arguments
in order. If there are more variable names than list elements, the
remaining variables are set to the empty string. If there are more
list elements than variables, a list of unassigned elements is
returned.
EXAMPLES
An illustration of how multiple assignment works, and what happens when
there are either too few or too many elements.
lassign {a b c} x y z ;# Empty return
puts $x ;# Prints "a"
puts $y ;# Prints "b"
puts $z ;# Prints "c"
lassign {d e} x y z ;# Empty return
puts $x ;# Prints "d"
puts $y ;# Prints "e"
puts $z ;# Prints ""
lassign {f g h i} x y ;# Returns "h i"
puts $x ;# Prints "f"
puts $y ;# Prints "g"
The lassign command has other uses. It can be used to create the ana-
logue of the "shift" command in many shell languages like this:
set ::argv [lassign $::argv argumentToReadOff]
ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
+---------------+------------------+
|ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+---------------+------------------+
|Availability | runtime/tcl-8 |
+---------------+------------------+
|Stability | Uncommitted |
+---------------+------------------+
SEE ALSO
lindex(n), list(n), lrange(n), lset(n), set(n)
KEYWORDS
assign, element, list, multiple, set, variable
NOTES
Source code for open source software components in Oracle Solaris can
be found at https://www.oracle.com/downloads/opensource/solaris-source-
code-downloads.html.
This software was built from source available at
https://github.com/oracle/solaris-userland. The original community
source was downloaded from http://prdownloads.sourceforge.net/tcl/tcl-
core8.6.7-src.tar.gz.
Further information about this software can be found on the open source
community website at https://www.tcl.tk/.
Tcl 8.5 lassign(1t)