UEFI Shell File Input and Redirection Guide

The Unified Extensible Firmware Interface (UEFI) Shell provides a powerful command-line environment that handles input and output data through standard streams, allowing script developers to control data flow using redirection operators. In automated .nsh scripts, managing file input and output redirection is critical for logging diagnostic results, passing automated responses to interactive tools, and chaining system commands. This article explains how the UEFI Shell manages standard streams, processes redirection operators, handles text encodings, and executes input-driven commands within batch scripts.

Standard Streams in UEFI Shell

The UEFI Shell architecture models input and output based on standard console abstractions similar to Unix and DOS environments:

  • Standard Input (StdIn): The default stream for receiving user keystrokes and data input.
  • Standard Output (StdOut): The default stream for displaying informational text and command output.
  • Standard Error (StdErr): A dedicated output stream specifically used for error notifications and diagnostic logs, isolated from standard command results.

During script execution, commands read from StdIn and write to StdOut or StdErr by default unless explicitly redirected.

Output Redirection Operators

Output redirection allows the UEFI Shell to divert data away from the console screen directly into storage files on accessible file systems (such as FAT32 EFI System Partitions).

  • Overwrite (>): Diverts standard output to a file, replacing any existing content. If the target file does not exist, the shell creates it.

    smbiosview > fs0:\logs\smbios.txt
  • Append (>>): Appends standard output to the end of the specified file without overwriting existing data.

    pci >> fs0:\logs\system_audit.txt
  • Error Redirection (2> and 2>>): Explicitly isolates standard error stream output. Using 2> overwrites an error log, whereas 2>> appends error output to an existing log.

    fs0:\tools\firmware_update.nsh 2>> fs0:\logs\errors.txt
  • Combined Output (>& or redirecting both streams): The shell allows directing both standard output and standard error simultaneously to capture full logs:

    drivers > fs0:\logs\driver_log.txt 2>&1

Input Redirection

Input redirection enables automated script execution by supplying command prompts with predefined data instead of requiring interactive manual input.

  • Read from File (<): Directs the shell to read inputs from an existing file rather than waiting for keyboard entry via standard input.

    fs0:\tools\interactive_utility.efi < fs0:\config\input_responses.txt

When an interactive utility requires confirmation (such as a [y/n] prompt) or batch parameter feeds, input redirection provides these sequences sequentially until the file reaches the End-of-File (EOF) marker.

Piping Output Between Commands

The pipe operator (|) routes the standard output of one command directly into the standard input of another without creating intermediary files on disk.

dmpstore | grep -i SecureBoot

In this context, the shell executes the first command, captures its StdOut buffer, and channels it dynamically into the receiving application's StdIn buffer.

File Encoding Considerations

The UEFI specification natively uses the UCS-2 and UTF-16 Little Endian (UTF-16 LE) character encodings for console text and strings, though many modern UEFI Shell implementations also support ASCII and UTF-8.

When redirecting text output to files using > or >>, the UEFI Shell automatically includes a Byte Order Mark (BOM) for UTF-16 LE files. If a script redirects input from a file into a tool that expects pure ASCII or UTF-8 formatting, parsing errors may occur. Input files prepared outside the firmware environment must match the character encoding supported by the specific executable receiving the redirected data.

Script Execution and Silent Processing

During .nsh script execution, script developers can suppress standard shell command echoing and progress outputs by using the -b (batch/break) option or by controlling shell verbosity directly:

echo -off
fs0:\diagnostics.efi > fs0:\output.txt
echo -on

This ensures that only targeted data reaches the designated output files, preventing shell control flow output from corrupting log files or parsing pipelines.