Notes on UEFI Shell Scripting

Notes on UEFI Shell Script

Script File

UEFI Shell script files have `.nsh' extension name, and can be encoded in ASCII or UCS-2.

Invocation

A UEFI shell script can be invoked in a UEFI Shell (except a level 0 shell, i.e. a minimal shell), or within another script, by its filename, with or without extension.

Startup Script

By default, UEFI Shell will automatically execute the startup script on launching, after a delay (5 seconds by default). This delay can be skipped by pressing any key (except Esc). If Esc is pressed during the delay, the startup script won't be executed.

The startup script must be named `startup.nsh'. Shell will search for startup script in this order:

  1. the same directory that the Shell is launched
  2. paths defined in environment variable `path'

and execute the script it first found. The minimum default `path' must contain `\efi\tools', `\efi\boot', and `\' for each mapped file system.

Force System Booting to UEFI Shell

In some Intel platforms, you can add a signature `# FORCE_EFI_BOOT' (Note that there is one space after `#') to the startup script to force system booting to UEFI Shell. It must be in the first line of file `startup.nsh'.

Commands

echo

Echo Off

Like batch files, shell echoing is enabled by default. To stop shell echoing during script executing, add `@echo -off' at the beginning of the script. Prepending `@' to a line suppresses the echoing of that line only. To turn echoing back on, use `echo -on'.

Quoting

The message to be echoed can either be quoted with double quotation marks ("), or be not quoted. However, if there is any switch-like argument, such as `-i', in the message, the message must be quoted, or the echo will error with `echo: Unknown flag - '-i''.

Empty Line Issue

Normally, `echo' will end output with a newline, but if the last line takes up all of the console column (e.g., echoing exact 80 characters in a 80x25 mode shell), `echo' with ends output with an empty line.

Shell> mode 80 25
Shell> echo 0123456789
0123456789
Shell> echo 11111111112222222222333333333344444444445555555555666666666677777777
778888888888
11111111112222222222333333333344444444445555555555666666666677777777778888888888

Shell> 

set

Set a volatile variable with `set -v NAME VALUE'. Unset a variable with `set -d NAME'. If `set' is used without any argument, it will print all environment variables.

Nesting

Variables set (or changed) in a parent shell (or a parent script) will be reflected in its child shells (or the scripts it called), and vice versa.

Back to Top | Home Page | GitHub | Email Me