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
    - apt
    - ${1}
    ansible-playbook ~/path/to/provisioning/scripts/tmp.yml
    rm ~/path/to/provisioning/scripts/tmp.yml
  • Thx for mentioning the exactly related question. As far as I understand from its answere, comments and the linked Wiki article I only have a temporary file and the writing process won't be killed, just blocked, after 64k. The last one means I have a backgrounded process constantly writing data to that pipe and the consuming process can read it, which removes the data from top of the pipe (what FIFO exactly is) and the writing process continues writing. The temporary file created ... where does it remains? As far as I understand it should be of size 0 bytes while the data is stored in memory. – codekandis Dec 2 '19 at 21:52
  • There's no temporary file: process substitution (as in foo <(bar)) does not use temporary files, but pipes. Pipes are not can cannot be implemented with temporary files -- not even conceptually. – mosvy Dec 3 '19 at 9:02
  • @mosvy Then please, how to undestand this - unix.stackexchange.com/a/63933/250324 >[...] Although the pipe exists as a file node on disk, the data which passes through it does not; it all takes place in memory. [...] – codekandis Dec 3 '19 at 12:05
  • @mosvy I tested now. mkfifo named_pipe and I found prw-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 3 '19 at 12:09
  • Please give an example of what you're trying to achieve: feel free to use any language you're comfortable with. Explain why simply echo content | foo or echo content | foo /dev/stdin or foo <(echo content1) <(echo content2) won't do. – mosvy Dec 3 '19 at 17:12

Browse other questions tagged or ask your own question.