EXECLINE-PUSHENV(7)
π EXECLINE-PUSHENV(7) π
Okay so this is the execline-pushenv(7) page from the Miscellaneous Information Manual, and we are about to talk about pushing and popping the environment like it's a group chat with too many pinned messages π«Άβ¨
πΈ NAME πΈ
execline-pushenv β pushing and popping the environment π
π¦ DESCRIPTION π¦
So the execlineb(1) launcher can slide your positional parameters β aka the arguments you gave your script β straight into the environment. The # variable holds the number of arguments; the 0 variable holds the name of your execline script; the 1 variable holds the first argument; and yeah, it keeps going like that, bestie.
Up to execline-1.04, this could cause drama with nested scripts: the inner script would overwrite the outer script's parameters, and there was literally no way to get them back. Especially iconic problem: writing execline commands in the execline language via the runblock(1) command was impossible. Not the vibe π
π Push π
To fix that whole situation, execline now has a kind of environment stack. When execlineb(1) reads the arguments, it does not overwrite the positional parameters β it pushes them onto the stack:
#will be set to the current number of arguments- but if a variable named
#existed before, it is renamed#:1 - and if a variable named
#:1also existed, it is renamed#:2 - ... and so on until
#:n+1doesn't exist.
Same goes for the other positional parameters. Then the script runs, and commands like elgetpositionals(1) use the current frame of positional parameters without paying attention to the deeper levels. It's giving βlook at the top layer onlyβ energy π
π¦ Pop π¦
When you're done with the arguments, it is advisable to drop the current frame and pop the environment stack so it goes back to its previous state:
#will be unset- but if
#:1exists, it will be renamed# - and if
#:2exists, it will be renamed#:1... and so on until#:n+1doesn't exist.
Again, same goes for the other positional parameters. The runblock(1) command will perform that pop operation automatically; the standard βmanualβ way to perform it is to use the βemptyenv -Pβ command. Slay, automatic cleanup π
π Substituting positional parameters without touching the environment π
Most of the time, you just need to substitute the positional parameters in your execline script β you don't need to go through the whole elgetpositionals(1) and emptyenv(1) chain. execline comes with an integrated substitution mechanism that does not touch the environment at all: the β-S nβ option. Obsessed with the efficiency tbh β¨
Scripts beginning with:
#!/command/execlineb -Sn
foobar...
are equivalent to:
#!/command/execlineb
elgetpositionals -Pn
emptyenv -P
foobar...
So, to summarize, from most efficient (but less flexible) to least efficient (but more flexible):
- Use β
execlineb -Pβ if you don't need positional parameters at all; for instance, in s6[1] or runit[2] run scripts. - Use β
execlineb -S nβ if you need only simple positional parameter substitution in your script - noshift(1)orelgetopt(1), no βimportas 1 1β. - Use β
execlineb -pβ, thenelgetpositionals(1)if you don't mind overwriting the current stack of positional parameters. - Use
execlineb(1), thenelgetpositionals(1), then βemptyenv -Pβ if you need the full power of positional parameter handling.
π§ EXAMPLES π§
Suppose you want to run the long-lived program prog after printing the list of its arguments.
#!/command/execlineb
elgetpositionals
foreground { echo $0 $@ }
prog $@
will work, but will pollute prog's environment with a set of positional parameters that have no meaning to it. A better script is:
#!/command/execlineb
elgetpositionals
foreground { echo $0 $@ }
emptyenv -P
prog $@
which will run prog with the same environment as the script's caller. Clean, considerate, main character behavior π
π SEE ALSO π
elgetopt(1)elgetpositionals(1)emptyenv(1)execlineb(1)runblock(1)shift(1)- [1]
https://skarnet.org/software/s6/ - [2]
http://smarden.org/runit/
This man page is ported from the authoritative documentation at: https://skarnet.org/software/execline/el_pushenv.html
π AUTHORS π
- Laurent Bercot
Alexis <flexibeast@gmail.com>(man page port)
Cute sign-off bestie: this page is from Debian, dated February 8, 2021 β mwah ππ
π¦ where this page comes from
- nixpkgs unstable: execline 2.9.9.2
- nixpkgs unstable: execline-man-pages 2.9.9.1.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms