2 ms·
Easy way to do file descriptor passing ("Bernstein chaining") with any UNIX programs, not just ones written by djb: http://skarnet.org/software/execline/pipeli
by gwu78 10y ago
Easy way to do file descriptor passing ("Bernstein chaining") with any UNIX programs, not just ones written by djb:
http://skarnet.org/software/execline/pipeline.html http://skarnet.org/software/execline/pipeline.html
Execline resembles a "program launcher".
We can make a braindead launcher in a few minutes using the sh language. This is just the first way that came to mind.
#!/bin/sh
test $# -ge 1||
exec echo usage: $0 program arguments
test $# -le 5||
exec echo max 5 arguments
{
a=$#;
b=$(command -v $1);
echo 'main(){
char *b['$((a+1))'];'
a=$((a-1));
test $a -ge 0||
exec echo 'b['$#']=(void *)0;
execve("'$b'",b,(void *)0);
}'
echo 'b[0]="'$1'";'
# repeat
a=$((a-1));
test $a -ge 0||
exec echo 'b['$#']=(void *)0;
execve("'$b'",b,(void *)0);
}'
echo 'b[1]="'$2'";'
a=$((a-1));
test $a -ge 0||
exec echo 'b['$#']=(void *)0;
execve("'$b'",b,(void *)0);
}'
echo 'b[2]="'$3'";'
a=$((a-1));
test $a -ge 0||
exec echo 'b['$#']=(void *)0;
execve("'$b'",b,(void *)0);
}'
echo 'b[3]="'$4'";'
a=$((a-1));
test $a -ge 0||
exec echo 'b['$#']=(void *)0;
execve("'$b'",b,(void *)0);
}'
echo 'b[4]="'$5'";'
a=$((a-1));
test $a -ge 0||
exec echo 'b['$#']=(void *)0;
execve("'$b'",b,(void *)0);
}'
echo 'b[5]="'$6'";'
} #| exec gcc -xc - -o run -static \
&& exec run
re: envdir, storing variables in the filesystem
"no stinkin loops"
or "stupid shell scripter" PoC, take 2
#!/bin/sh
# e is a dir of "environmental variables"
# e is mounted on tmpfs i.e., it's memory not disk
# output:
# ==> 0
# ==> 1
# ==> 2
# ==> 3
# ==> 4
# ==> 5
test -f e/$0||echo 0 > e/$0
read n < e/$0
test $n -le 5||exec rm e/$0
echo ==\> $n
echo $((n+1)) > e/$0
test -f $0||exit # just in case
$0