Expand values with systemd specifiers
Specifiers let a single systemd unit adapt to its context. Instead of hard-coding
a hostname, user or instance name, you write a %-token that systemd resolves
when it loads the unit. This is what makes template units ([email protected])
powerful: %i becomes whatever follows the @. This tool lists every specifier
with the value it expands to and a concrete example.
How it works
A specifier is a percent sign followed by a single character. When systemd parses
a unit file it substitutes each known specifier with a runtime value before the
option takes effect. The values come from several sources: the unit name itself
(%n, %p, %i, %j and their escaped uppercase variants), the host
(%H hostname, %m machine ID, %b boot ID, %v kernel release), the
executing user (%u/%U, %g/%G, %h home, %s shell), and standard
directories (%t runtime, %S state, %C cache, %L logs, %E config). To
emit a literal percent you escape it as %%. Because the escaped forms (%I,
%P, %J) keep systemd’s path escaping, they round-trip safely when the
instance encodes a filesystem path.
Tips and notes
In template units, derive paths from %i so one file serves every instance — for
example WorkingDirectory=/srv/%i. Choose the escaped variant (%I) when the
value must match an on-disk name and the unescaped variant (%i) for
Description= and other human-facing text. Verify what a unit will actually run
with systemctl cat name@instance and systemd-analyze — both show the resolved
values so you can catch a mis-expanded specifier before it causes a surprise.