I want to create something file-like (that can be read like a common file), which everytime it is read, it gets its output from a command.
For instance, if I do echo $RANDOM > test
,
then I can call cat test
and it will display the generated random number.
Except that I would need that everytime I call cat test
(or read it any other way), my generator command is called (echo $RANDOM
in my example, but actually it will generate more data -- around 1kb).
I think the best bet would be to create some kind of device special file / device driver? What I need is indeed similar to /dev/zero or /dev/random. Is it possible to create it simply? Using standard gnu/sh library would be ideal?
Thanks in advance for any hint!
echo $RANDOM > test
. However every other part of the question suggests that you don't want to do this. But may have the effect that this is done just before each read. Is that correct. Please clarify by editing the question.