E
E
Eugene Wolf2018-10-18 13:09:37
linux
Eugene Wolf, 2018-10-18 13:09:37

Is it possible to replace a file with the output of a program?

Good day!
Example:
There is a text file, file1 , with the content " Hello world ". I have a bash script with the following content:

#!/bin/bash
echo 123;

If we try to read the contents of a file, like this: cat file1we get its contents.
Is it possible to somehow replace the file in such a way that any program, when trying to read it, would receive not the contents of this file, but the output of some script?
I understand that there are "conveyors" of type cat | script.sh, but the question is whether, without affecting the logic of some other program that reads some file, it can replace reading this file with output from my script, without writing new content to this file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ISE73, 2018-10-18
@ISE73

Perhaps named pipes will help you:

mkfifo myfile
script.sh >> myfile &
cat myfile

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question