1 .. SPDX-License-Identifier: GPL-2.0-or-later
29 The if command is used to conditionally execute statements.
32 Any command. The test statement set the $? variable. If the value of
33 $? becomes 0 (true) the statements after the **then** statement will
34 be executed. Otherwise the statements after the **else** statement.
39 The examples shows how the value of a numeric variable can be tested with
40 the :doc:`itest <itest>` command.
44 => a=1; if itest $a == 0; then echo true; else echo false; fi
46 => a=0; if itest $a == 0; then echo true; else echo false; fi
49 In the following example we try to load an EFI binary via TFTP. If loading
50 succeeds, the binary is executed.
54 if tftp $kernel_addr_r shellriscv64.efi; then bootefi $kernel_addr_r; fi
59 The value of $? is the return value of the last executed statement.
63 => if true; then true; else true; fi; echo $?
65 => if false; then true; else true; fi; echo $?
67 => if false; then false; else false; fi; echo $?
69 => if true; then false; else false; fi; echo $?
71 => if false; then true; fi; echo $?