← Back to context

Comment by floam

2 years ago

> so i found myself caching files to disk for export/import

Could use a named pipe.

I’m reminded of what I often do at the shell with psub in fish. psub -f creates and returns the path to a fifo/named pipe in $TMPDIR and writes stdin to that; you’ve got a path but aren’t writing to the filesystem.

e.g. you want to feed some output to something that takes file paths as arguments. We want to compare cmd1 | grep foo and cmd2 | grep foo. We pipe each to psub in command substitutions:

    diff -u $(cmd1 | grep foo | psub -f) $(cmd2 | grep foo | psub -f)

which expands to something like

   diff -u /tmp/fish0K5fd.psub /tmp/fish0hE1c.psub

As long as the tool doesn’t seek around the file. (caveats are numerous enough that without -f, psub uses regular files.)

> I’m reminded of what I often do at the shell with psub in fish.

ksh and bash too have this as <(…) and >(…) under Process Substitution.

An example from ksh(1) man page:

    paste <(cut -f1 file1) <(cut -f3 file2) | tee >(process1) >(process2)

bash (at least) has a built-in mechanism to do that

diff <(cmd1 | grep foo) <(cmd2 | grep foo)