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