Assume I like to execute the command foo
which expects a specific file as an argument. I like to execute that command for a temporary purpose only so I like to have mentioned file as a temporary file, too.
In my specific use case I'd create the file temporary, execute the command with the temporary file and delete the file afterwards. This works fine.
Is there a way to pass that file with some kind of stream handler (borrowed speech from programming languages), so I don't have to create that file as a real file just temporary?
What I'm thinking about is some sort of foo "$( echo some content mimicking a file )"
, which I know, in fact, won't work but describes what I like to achieve.
Edit: My actual use case
I have multiple ansible roles to provision my entire system from scratch. Sometimes I have the need to run run one specific role for update purposes only. So actually I'm writing a temporary playbook, executing it and deleting it afterwards.
cat > ~/path/to/provisioning/scripts/tmp.yml << EOF
- name: Executing the tasks \`tmp\`
hosts: localhost
become: yes
roles:
- apt
- ${1}
EOF
ansible-playbook ~/path/to/provisioning/scripts/tmp.yml
rm ~/path/to/provisioning/scripts/tmp.yml
foo <(bar)
) does not use temporary files, but pipes. Pipes are not can cannot be implemented with temporary files -- not even conceptually. – Dec 03 '19 at 09:02mkfifo named_pipe
and I foundprw-r--r-- ... named_pipe
. So I end up with the same problem I intended to prevent with my question. Creating a file / named pipe, processing data, deleting the file / named pipe. In fact it's the same costs than. – codekandis Dec 03 '19 at 12:09echo content | foo
orecho content | foo /dev/stdin
orfoo <(echo content1) <(echo content2)
won't do. – Dec 03 '19 at 17:12pipe(2)
system call), exploiting the fact that they're still accessible in the file system via the/dev/fd
mechanism:foo <(bar)
will turn intofoo /dev/fd/63
or similar, with/dev/fd/63
opening the same file the file descriptor 63 refers to in thefoo
process. – Dec 03 '19 at 17:13mkfifo
one liner. – codekandis Dec 04 '19 at 08:09