I have a program (let's name it middle
) which I can't modify.
This program performs the following sequence of steps:
middle
sends some text to stdout (echo Text1
)middle
invokes shell scriptinner.sh
passing some text string (4 KBytes or less) as argument (inner.sh "Deferred Message"
)middle
sends some text to stdout (echo Text2
)
My task is to create two bash scripts outer.sh
and inner.sh
to arrange deferred message after all the other messages generated by middle
process.
The resulting stdout must be the following:
Text1
Text2
Deferred Message
The requirements:
outer.sh
should invokemiddle
(andmiddle
will invokeinner.sh
).inner.sh
must remember its argument (deferred message) somewhere- After
middle
is terminated,outer.sh
must recall the deferred message and print it to stdout - There will be a lot of
outer.sh
processes running simultaneously. The deferred message must be stored in a place which is local to current instance ofouter.sh
process - Creation of temporary objects in file system is prohibited. (Is it possible to store the deferred message somewhere in memory?)
inner.sh
# Where should I save message "$1"?
outer.sh
middle "$@"
# How should I recall and print the deferred message?
Where should I save the deferred message in child process and how to read it back in parent process?