blob: f9e504979c3311cc4b6131467385113104847fca [file] [log] [blame]
Heinrich Schuchardtde702492021-01-20 18:09:30 +01001for command
2===========
3
4Synopis
5-------
6
7::
8
9 for <variable> in <items>; do <commands>; done
10
11Description
12-----------
13
14The for command is used to loop over a list of values and execute a series of
15commands for each of these.
16
17The counter variable of the loop is a shell variable. Please, keep in mind that
18an environment variable takes precedence over a shell variable of the same name.
19
20variable
21 name of the counter variable
22
23items
24 space separated item list
25
26commands
27 commands to execute
28
29Example
30-------
31
32::
33
34 => setenv c
35 => for c in 1 2 3; do echo item ${c}; done
36 item 1
37 item 2
38 item 3
39 => echo ${c}
40 3
41 => setenv c x
42 => for c in 1 2 3; do echo item ${c}; done
43 item x
44 item x
45 item x
46 =>
47
48The first line ensures that there is no environment variable *c*. Hence in the
49first loop the shell variable *c* is printed.
50
51After defining an environment variable of name *c* it takes precedence over the
52shell variable and the environment variable is printed.
53
54Return value
55------------
56
57The return value $? after the done statement is the return value of the last
58statement executed in the loop.
59
60::
61
62 => for i in true false; do ${i}; done; echo $?
63 1
64 => for i in false true; do ${i}; done; echo $?
65 0