SUBST(1)
π SUBST(1) β the substitute-definitions-into-files girlie π
okay bestie, gather round, because this one is a manual page for subst, and she is genuinely so useful once you get her vibe. no cap.
β¨ NAME β¨
subst β substitute definitions into file(s). that's it, that's the whole job. she takes your definitions and she puts them in your files. slay.
π SYNOPSIS π
subst [ -e editor ] -f substitutions victim ...
yes the -f is mandatory, yes the victims are plural, yes she eats multiple files for breakfast. π
πΈ DESCRIPTION πΈ
so subst makes substitutions into files, in a way that is suitable for customizing software to local conditions. like, you wrote your program for your machine, and now it needs to run on someone else's machine, and instead of hand-editing every single value like a Victorian orphan, you let subst do it. every victim file gets altered according to the contents of the substitutions file. π¦
the substitutions file contains one line per substitution. a line consists of two fields separated by one or more tabs. field one = the name of the substitution. field two = the value. neither should contain the character #, and honestly, using text-editor metacharacters like & and \' is also unwise β the name in particular is best restricted to be alphanumeric. like, keep it cute and simple, okay? π a line starting with # is a comment and is ignored. periodt.
now here's the part where you have to pay attention, bestie, because this is the whole mechanic:
in the victims, each line on which a substitution is to be made (a target line) must be preceded by a prototype line. the prototype line should be delimited in such a way that it will be taken as a comment by whatever program processes the file later β so like, whatever language you're in, make it look like a comment to that language. sneaky? no, iconic. π
the prototype line must contain a ``prototype'' of the target line bracketed by =()< and >()=. everything else on the prototype line is ignored. then subst:
- extracts the prototype,
- changes all instances of substitution names bracketed by
@<and>@to their values, - and then replaces the target line with the result. πͺ
it's giving "template engine but make it 1990".
β¨ OPTIONS β¨
-eβ substitutions are done using thesed(1)editor, which must be found in either the/binor/usr/bindirectories. to specify a different executable, use the ``-e'' flag. (yes, the flag that picks the editor is also described by the flag. she contains multitudes. π)
π EXAMPLE π
if the substitutions file is
FIRST 111
SECOND 222
and the victim file is
x = 2;
/* =()<y = @<FIRST>@ + @<SECOND>@;>()= */
y = 88 + 99;
z = 5;
then ``subst -f substitutions victim'' changes victim to:
x = 2;
/* =()<y = @<FIRST>@ + @<SECOND>@;>()= */
y = 111 + 222;
z = 5;
see how the prototype line stayed exactly the same and only the target line got the glow-up? that's the whole trick. the prototype is the receipt, the target is the purchase. π₯
π§ FILES π§
victimdir/substtmp.newβ new version being builtvictimdir/substtmp.oldβ old version during renaming
she builds the new one, renames the old one, it's a whole backstage situation. π
π SEE ALSO π
π DIAGNOSTICS π
complains and halts if it is unable to create its temporary files or if they already exist. so if you've got stale substtmp files lying around, she will simply refuse. respectfully. π
π HISTORY π
written at U of Toronto by Henry Spencer.
Rich $alz added the ``-e'' flag July, 1991.
a legacy. a lineage. we love to see it. π
π BUGS π
when creating a file to be substed, it's easy to forget to insert a dummy target line after a prototype line; if you forget, subst ends up deleting whichever line did in fact follow the prototype line.
okay so this is the jump scare. β οΈ a prototype with no target under it means the next actual line of your file gets yeeted into the void. so always, always, always put a dummy target line right after your prototype line. protect your lines, bestie. π«Ά
this has been SUBST(1) from the General Commands Manual, dated 25 Feb 1990 β yeah she's vintage, she's older than your fave, and she still runs. mwah. π
β¨
π¦ where this page comes from
- debian bookworm: inn 1:1.7.2q-47
- debian trixie: inn 1:1.7.2q-52
- ubuntu jammy: inn 1:1.7.2q-46build3
- ubuntu noble: inn 1:1.7.2q-50
- ubuntu questing: inn 1:1.7.2q-52
- ubuntu resolute: inn 1:1.7.2q-52build1
- ubuntu stonking: inn 1:1.7.2q-52build2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms