aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2024-03-16 10:57:41 +0100
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2024-03-21 07:29:01 +0100
commita9122d2c45d267adf80e84ae778eb5ac60bca94f (patch)
treee154b2a8120569af9434dace349275d404504da5
parent68fc0b877b5ddc93eb542ffa26dcf83e7e2860a8 (diff)
downloadu-boot-a9122d2c45d267adf80e84ae778eb5ac60bca94f.zip
u-boot-a9122d2c45d267adf80e84ae778eb5ac60bca94f.tar.gz
u-boot-a9122d2c45d267adf80e84ae778eb5ac60bca94f.tar.bz2
doc: man-page for if
Provide a man-page for the if command. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
-rw-r--r--doc/usage/cmd/if.rst72
-rw-r--r--doc/usage/index.rst1
2 files changed, 73 insertions, 0 deletions
diff --git a/doc/usage/cmd/if.rst b/doc/usage/cmd/if.rst
new file mode 100644
index 0000000..6b3dbe7
--- /dev/null
+++ b/doc/usage/cmd/if.rst
@@ -0,0 +1,72 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+.. index::
+ single: if (command)
+
+if command
+==========
+
+Synopsis
+--------
+
+::
+
+ if <test statement>
+ then
+ <statements>
+ fi
+
+ if <test statement>
+ then
+ <statements>
+ else
+ <statements>
+ fi
+
+Description
+-----------
+
+The if command is used to conditionally execute statements.
+
+test statement
+ Any command. The test statement set the $? variable. If the value of
+ $? becomes 0 (true) the statements after the **then** statement will
+ be executed. Otherwise the statements after the **else** statement.
+
+Example
+-------
+
+The examples shows how the value of a numeric variable can be tested with
+**itest**.
+
+::
+
+ => a=1; if itest $a == 0; then echo true; else echo false; fi
+ false
+ => a=0; if itest $a == 0; then echo true; else echo false; fi
+ true
+
+In the following example we try to load an EFI binary via TFTP. If loading
+succeeds, the binary is executed.
+
+::
+
+ if tftp $kernel_addr_r shellriscv64.efi; then bootefi $kernel_addr_r; fi
+
+Return value
+------------
+
+The value of $? is the return value of the last executed statement.
+
+::
+
+ => if true; then true; else true; fi; echo $?
+ 0
+ => if false; then true; else true; fi; echo $?
+ 0
+ => if false; then false; else false; fi; echo $?
+ 1
+ => if true; then false; else false; fi; echo $?
+ 1
+ => if false; then true; fi; echo $?
+ 1
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 0d174ee..66d73e7 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -71,6 +71,7 @@ Shell commands
cmd/gpt
cmd/history
cmd/host
+ cmd/if
cmd/imxtract
cmd/load
cmd/loadb