This page is for brainstorming a scripting language for gPXE. Feel free to edit to your heart's delight - everything should be versioned by the wiki anyway!


The current gPXE shell strips whitespace from a line and splits into an argv[] array:

command [arg1 [arg2 [arg3 ...]]]


Currently, settings like the IP address and boot filename are available as variables. In the future, scripts should be able to create temporary variables as scratch space.

set net0/ip
set my_ip
show net0/netmask
clear net0/gateway

Variable expansion is already available in mainline gPXE:

dhcp ${my_iface}

“References” could work like this:

set ref_to_ip net0/ip
show ${ref_to_ip}
=> ...value of net0/ip...


Standard arithmetic operators should work for integral types:

set i ${(i / 2 + 1) * 2}

The operators are: +, -, *, /, %, (, and ).

String manipulation

The format string built-in function allows string concatentation and formatting:

set net0/ip ${fmt("%d.%d.%d.%d", 192, 168, 0, 10 + host_num)}

Comparison and logic

The standard operators for integral and string types (string ordering probably isn't necessary though):

== != < > <= >=

They should either evaluate to special boolean values “true”/“false”, or we need to define truth rules for all types (e.g. integral types are true if not equal to zero).

Control flow

The only control flow statement is the if statement:

if <expression> goto <label>

For example:

set i 0
    dhcp net${i}
    kernel ${kernel_url}
    set i ${i + 1}
    if ${i < $iface_count} goto loop

Needs discussion

  • We probably need an exit code built-in variable like $? in POSIX shell.
  • Bitwise operators |, &, ^, ~, «, and » may be needed.
  • Focus needs to be on what we can leave out rather than what to add.
  • More use cases so we know what users need.

QR Code
QR Code dev:scripting:start (generated for current page)