'\" '\" Copyright (c) 1993 The Regents of the University of California. '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" '\" RCS: @(#) $Id: lindex.n,v 1.6.6.2 2001/07/18 22:20:35 dgp Exp $ '\" .so man.macros .TH lindex n 8.2 Tcl "Tcl Built-In Commands" .BS '\" Note: do not modify the .SH NAME line immediately below! .SH NAME lindex \- Retrieve an element from a list .SH SYNOPSIS \fBlindex \fIlist index ?index...?\fR .BE .SH DESCRIPTION .PP .VS 8.4 When presented with two arguments, this command treats \fIlist\fR as a Tcl list and returns the .VE \fIindex\fR'th element from it (0 refers to the first element of the list). In extracting the element, \fIlindex\fR observes the same rules concerning braces and quotes and backslashes as the Tcl command interpreter; however, variable substitution and command substitution do not occur. If \fIindex\fR is negative or greater than or equal to the number of elements in \fIvalue\fR, then an empty string is returned. If \fIindex\fR has the value \fBend\fR, it refers to the last element in the list, and \fBend\-\fIinteger\fR refers to the last element in the list minus the specified integer offset. .PP .VS 8.4 If additional \fIindex\fR arguments are supplied, then each argument is used in turn to select an element from the previous indexing operation, allowing the script to select elements from sublists. The expression, .CS lindex $a 1 2 3 .CE is synonymous with .CS lindex [lindex [lindex $a 1] 2] 3 .CE .SH EXAMPLES .CS lindex {a b c} 0 => a lindex {a b c} 2 => c lindex {a b c} end => c lindex {a b c} end-1 => b lindex {{a b c} {d e f} {g h i}} 2 1 => h lindex {{{a b} {c d}} {{e f} {g h}}} 1 1 0 => g .CE .VE .SH "SEE ALSO" list(n), lappend(n), linsert(n), llength(n), lsearch(n), lsort(n), lrange(n), lreplace(n) .SH KEYWORDS element, index, list