1lindex(n)                    Tcl Built-In Commands                   lindex(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       lindex - Retrieve an element from a list
9

SYNOPSIS

11       lindex list ?index...?
12_________________________________________________________________
13

DESCRIPTION

15       The  lindex command accepts a parameter, list, which it treats as a Tcl │
16       list. It also accepts zero or more indices into the list.  The  indices │
17       may  be  presented either consecutively on the command line, or grouped │
18       in a Tcl list and presented as a single argument.                       │
19
20       If no indices are presented, the command takes the form:                │
21              lindex list                                                      │
22       or                                                                      │
23              lindex list {}                                                   │
24       In this case, the return value of lindex is simply  the  value  of  the │
25       list parameter.                                                         │
26
27       When presented with a single index, the lindex command treats list as a │
28       Tcl list and returns the index'th element from  it  (0  refers  to  the
29       first element of the list).  In extracting the element, lindex observes
30       the same rules concerning braces and quotes and backslashes as the  Tcl
31       command interpreter; however, variable substitution and command substi‐
32       tution do not occur.  If index is negative or greater than or equal  to
33       the  number of elements in value, then an empty string is returned.  If
34       index has the value end, it refers to the last element in the list, and
35       end-integer  refers to the last element in the list minus the specified
36       integer offset.
37
38       If additional index arguments are supplied, then each argument is  used │
39       in  turn  to  select  an  element from the previous indexing operation, │
40       allowing the script to select elements from sublists.  The command,     │
41              lindex $a 1 2 3                                                  │
42       or                                                                      │
43              lindex $a {1 2 3}                                                │
44       is synonymous with                                                      │
45              lindex [lindex [lindex $a 1] 2] 3                                │
46

EXAMPLES │

48              lindex {a b c}  => a b c
49              lindex {a b c} {} => a b c
50              lindex {a b c} 0 => a
51              lindex {a b c} 2 => c
52              lindex {a b c} end => c
53              lindex {a b c} end-1 => b
54              lindex {{a b c} {d e f} {g h i}} 2 1 => h
55              lindex {{a b c} {d e f} {g h i}} {2 1} => h
56              lindex {{{a b} {c d}} {{e f} {g h}}} 1 1 0 => g
57              lindex {{{a b} {c d}} {{e f} {g h}}} {1 1 0} => g
58

SEE ALSO

60       list(n),  lappend(n),  linsert(n),  llength(n),  lsearch(n),   lset(n), │
61       lsort(n), lrange(n), lreplace(n)
62
63

KEYWORDS

65       element, index, list
66
67
68
69Tcl                                   8.4                            lindex(n)
Impressum