WITHSTDINAS(1)

πŸ“¦ version 2.9.9.2, in nixpkgs unstable

πŸ’– withstdinas β€” read ALL of stdin into an env var and go run another program with it πŸ’–

okay so bestie, this is withstdinas(1) from the General Commands Manual and it is genuinely one of my fave little execline tools, no cap. let me tell you everything ✨


πŸŽ€ NAME πŸŽ€

withstdinas β€” reads the entirety of standard input into an environment variable, then runs another program with that extra environment variable chillin' in its env 🫢


🌸 SYNOPSIS 🌸

inside an execlineb(1) script, you'd do:

withstdinas [-i | -I | -D default] [-N | -n] [-E | -e] variable prog...

πŸ¦‹ DESCRIPTION πŸ¦‹

So. withstdinas reads its stdin until EOF. like, all of it. every last byte, until the party's over 😭

Then it exec(3)s into prog..., with variable added to the environment β€” and the value of variable is literally whatever got read on stdin. iconic behaviour, honestly πŸ‘‘

and here's the little trick that makes it all work, iykyk: you can start prog... with importas -u variable variable to do the variable substitution πŸ’…


✨ OPTIONS ✨

πŸ“ the newline situation

  • -N β€” do not chomp an ending newline off stdin. leave that newline exactly where you found it, bestie πŸ’€
  • -n β€” chomp an ending newline off stdin. this one's the default, so it's already doing this unless you say otherwise 🌈

🧚 the autoimport situation

  • -e β€” no autoimport. this is the default, so like, business as usual 🌸
  • -E β€” autoimport! instead of exec(3)ing into prog..., it exec(3)s into importas -ui variable variable prog.... basically it substitutes variable into the command line instead of dropping it into the environment. different vibe, same data πŸ’–

πŸ”₯ the "uh oh, null character" situation

okay, so the rest of the options are all about the drama of: what do we do when the input isn't suitable as the contents of an environment variable? and by that I mean... it contains a null character 😭 that's the vibes-killer right there.

  • -i β€” withstdinas just exits 1. it's not mad, it's just disappointed πŸ™ˆ
  • -I β€” variable gets removed from the environment, and execution proceeds anyway 🫢
  • -D default β€” the value of variable is set to default, and execution proceeds, slay ✨
and when you give none of those options? the value of variable is set to whatever the start of the input is, right up to the first null character, and execution proceeds. so it just... stops caring at the null. lowkey iconic πŸŽ€

πŸ‘‘ SEE ALSO πŸ‘‘

emptyenv(1), envfile(1), exec(1), execline-cd(1), execline-umask(1), execlineb(1), exit(1), export(1), fdblock(1), fdclose(1), fdmove(1), fdreserve(1), fdswap(1), getcwd(1), getpid(1), heredoc(1), piperw(1), posix-cd(1), posix-umask(1), redirfd(1), trap(1), tryexec(1), unexport(1), wait(1), exec(3)

πŸ’œ this man page is ported from the authoritative documentation at: https://skarnet.org/software/execline/withstdinas.html β€” go give it a read, fr fr πŸ¦‹


🌟 AUTHORS 🌟

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

Debian, February 14, 2021 β€” that's the source, the version, and the date, all bundled up with a little bow πŸŽ€ tysm for reading bestie, go pipe something into an env var and SLAY πŸ’…βœ¨
πŸ“¦ where this page comes from