Specifications

Version 2.0
71
4 Scripts
UEFI Shell scripts allow user to simplify routine or repetitive tasks. A shell script
program is a UCS-2 or ASCII text file that contains one or more commands and has a
.nsh file name extension. When the file name is typed at the command prompt,
commands in the file are executed sequentially.
All shell commands can be executed in scripts. In addition, some script-only
commands are also provided to do basic flow control. Script-only means those
commands can be only executed in UEFI Shell Script files, and cannot be executed
from the shell prompt.
Up to ten positional arguments are supported for scripts. Positional argument
substitution is performed before the execution of each line in the script file. Positional
arguments are denoted by %n, where n is a digit between 0 and 9. By convention, %0
is the name of the script file currently being executed.
Script file execution can be nested; that is, script files may be executed from within
other script files. Recursion is allowed. Shell scripts run in their parent’s environment.
Output and input redirection are fully supported in scripts. Output redirection on a
command in a script file causes the output for that command to be redirected. Output
redirection on the invocation of a script causes the output for all commands executed
from that script to be redirected to the file, with the output of each command
appended to the end of the file.
By default, both the input and output for all commands executed from a script are
echoed to the console. Display of commands read from a script file can be suppressed
via the echo -off command (see echo). Also, additional ‘@’ before a command in a
script file can prevent the current command from being echoed.
If output for a command is redirected to a file, then that output is not displayed on
the console. Commands executed from a script will not be saved by the shell for key
history and these commands cannot be recalled by pressing Up-Arrow key.
4.1 Comments
Comments can be embedded in scripts. The # character on a line is used to denote
that all characters on the same line and to the right of the # are to be ignored by the
shell. Whether the echo state is on or off, comments are not echoed to the console.
4.2 Error Handling
By default, if an error is encountered during the execution of a command in a script,
the script will continue to execute. But if an error is encountered when executing the
script-only commands which affects the logic of the script, such as for, endfor, if,