FDRESERVE(1)

πŸ“¦ version 2.9.9.2, in nixpkgs unstable

πŸ’… FDRESERVE(1) πŸ’…

Okay bestie, this is fdreserve(1) from the General Commands Manual, and it's giving tiny-utility-with-main-character-energy. No cap. πŸ’–

πŸ’– NAME πŸ’–

fdreserve β€” update the environment with file descriptors that are guaranteed safe to use, then execute a program.

✨ SYNOPSIS ✨

fdreserve n prog...

🌸 DESCRIPTION 🌸

So fdreserve tries to reserve n file descriptors.

It sets the FD0, FD1, ..., FDnβˆ’1 environment variables: each FDi contains a valid file descriptor, that can be safely opened.

Then fdreserve exec(3)s into prog with its arguments. Slay. ✨

πŸŽ€ Common use πŸŽ€

fdreserve can be used when you do not want to hardcode file descriptors in your scripts. For instance, to create a pipe, you could use:

#!/command/execlineb
fdreserve 2
multisubstitute
{
  importas fdr FD0
  importas fdw FD1
}
piperw $fdr $fdw
prog...
Warning: fdreserve does not allocate descriptors, it merely returns descriptors that are free at the time it is run. A program like
#!/command/execlineb
fdreserve 3
multisubstitute
{
  importas fdr FD0
  importas fdw FD1
}
piperw $fdr $fdw
fdreserve 1
multisubstitute
{
  importas oldfd FD2
  importas newfd FD0
}
prog...
may fail, because oldfd and newfd may be the same. To avoid that, you should make sure that all descriptors returned by fdreserve are actually allocated before calling fdreserve again. (Thanks to Paul Jarc[1] for having spotted that case.) πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

All the manual-page besties in the neighborhood:

[1] https://code.dogmap.org/

This man page is ported from the authoritative documentation at: https://skarnet.org/software/execline/fdreserve.html

πŸ‘‘ AUTHORS πŸ‘‘

  • Laurent Bercot
  • Alexis <flexibeast@gmail.com> (man page port)

πŸ’– Cute little footer sign-off: source/version is Debian, dated February 14, 2021, and it's for FDRESERVE(1). Bye bestie, go reserve those fds responsibly! πŸ’…πŸ«Ά

πŸ“¦ where this page comes from