28 lines
507 B
Awk
28 lines
507 B
Awk
|
|
#!/usr/bin/awk -f
|
||
|
|
|
||
|
|
BEGIN {
|
||
|
|
# Turn off buffering with bash
|
||
|
|
coproc = "stdbuf -i0 -o0 -e0 bash"
|
||
|
|
|
||
|
|
i = 0
|
||
|
|
|
||
|
|
# Commands we'll send
|
||
|
|
com[i++] = "date"
|
||
|
|
com[i++] = "whoami"
|
||
|
|
com[i++] = "id"
|
||
|
|
com[i++] = "exit"
|
||
|
|
|
||
|
|
i = 0
|
||
|
|
|
||
|
|
# Write and read in a loop → buffering problems?
|
||
|
|
do {
|
||
|
|
print com[i++] |& coproc
|
||
|
|
coproc |& getline results
|
||
|
|
if (i in com) print ":", results
|
||
|
|
} while (i in com)
|
||
|
|
close(coproc)
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
# vim: syntax=awk:ts=8:sw=4:ai:et:tw=78:fo=tcrqn21
|