elvish icon indicating copy to clipboard operation
elvish copied to clipboard

Implement process substitution?

Open kwshi opened this issue 7 years ago • 3 comments

There are times when a program refuses to read from stdin and only reads from a filename, so piping doesn't work. In these cases, Bash's process substitution is desirable, wherein some fd gets opened, the output of a command is written to that fd, and another command can read from that fd, given its path:

Bash example:

$ echo <(echo hi)
/dev/fd/63
$ cat <(echo hi) # pretending, for a moment, that `cat` does not allow stdin input
hi

This may be desirable, I think.

kwshi avatar Aug 08 '18 09:08 kwshi

Sounds legit. However, <(echo hi) today can already be parsed as a < followed by an output capture, so we will have to introduce another whitespace-sensitive syntax. I don't consider this a blocker, but if we can come up with another syntax it would be better.

We can also follow fish, which implements process substitution using a function, psub. It uses a temporary file and relies on a on-job-exit hook to clean up the temp file.

xiaq avatar Aug 09 '18 23:08 xiaq

For the record, process substitution (<(cmd) and >(cmd)) are from ksh in the mid 80s, not bash. Also supported by zsh. Of the 3, bash was the last to add it. zsh has a third =(cmd) form, where the output of cmd is stored in a temp file, useful for commands that need seekable files.

rc and derivatives use <{...} / >{...} syntax (also predates bash and likely even zsh). fish uses (...|psub) syntax (also with tempfiles, as their attempt to use pipes ended in deadlocks).

stephane-chazelas avatar Jan 25 '23 17:01 stephane-chazelas