diff options
author | Heinrich Schuchardt | 2021-01-20 18:09:30 +0100 |
---|---|---|
committer | Heinrich Schuchardt | 2021-01-25 01:15:33 +0100 |
commit | de702493c449200a0e84c8e6dcc58deb49837691 (patch) | |
tree | d191a792cab9daeff58f022629d35e277d9ee7ac /doc/usage | |
parent | 627b57bde05063b2f512d8e3ec6f8060aea25b91 (diff) |
doc: document for statement
Create a man-page for the for statement.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Diffstat (limited to 'doc/usage')
-rw-r--r-- | doc/usage/for.rst | 65 | ||||
-rw-r--r-- | doc/usage/index.rst | 1 |
2 files changed, 66 insertions, 0 deletions
diff --git a/doc/usage/for.rst b/doc/usage/for.rst new file mode 100644 index 00000000000..f9e504979c3 --- /dev/null +++ b/doc/usage/for.rst @@ -0,0 +1,65 @@ +for command +=========== + +Synopis +------- + +:: + + for <variable> in <items>; do <commands>; done + +Description +----------- + +The for command is used to loop over a list of values and execute a series of +commands for each of these. + +The counter variable of the loop is a shell variable. Please, keep in mind that +an environment variable takes precedence over a shell variable of the same name. + +variable + name of the counter variable + +items + space separated item list + +commands + commands to execute + +Example +------- + +:: + + => setenv c + => for c in 1 2 3; do echo item ${c}; done + item 1 + item 2 + item 3 + => echo ${c} + 3 + => setenv c x + => for c in 1 2 3; do echo item ${c}; done + item x + item x + item x + => + +The first line ensures that there is no environment variable *c*. Hence in the +first loop the shell variable *c* is printed. + +After defining an environment variable of name *c* it takes precedence over the +shell variable and the environment variable is printed. + +Return value +------------ + +The return value $? after the done statement is the return value of the last +statement executed in the loop. + +:: + + => for i in true false; do ${i}; done; echo $? + 1 + => for i in false true; do ${i}; done; echo $? + 0 diff --git a/doc/usage/index.rst b/doc/usage/index.rst index b8f216b7132..6f49652758f 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -18,6 +18,7 @@ Shell commands bootmenu button exit + for mbr pstore sbi |