]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
doc: man-page for if
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 16 Mar 2024 09:57:41 +0000 (10:57 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 21 Mar 2024 06:29:01 +0000 (07:29 +0100)
Provide a man-page for the if command.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
doc/usage/cmd/if.rst [new file with mode: 0644]
doc/usage/index.rst

diff --git a/doc/usage/cmd/if.rst b/doc/usage/cmd/if.rst
new file mode 100644 (file)
index 0000000..6b3dbe7
--- /dev/null
@@ -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
index 0d174eefaa5caf7343a4d9e9061b0ecbfcf9a2dc..66d73e70cc4fb225608b80c7d214234ea4b331ee 100644 (file)
@@ -71,6 +71,7 @@ Shell commands
    cmd/gpt
    cmd/history
    cmd/host
+   cmd/if
    cmd/imxtract
    cmd/load
    cmd/loadb