<(commands ...)
in bash/zsh makes the output behavior as a file.
Does a POSIX equivalent exist?
Asked
Active
Viewed 2,061 times
14
-
4[POSIX does not specify process substitution, but you may used named pipes to accomplish the same thing.](http://mywiki.wooledge.org/ProcessSubstitution) – bishop Aug 05 '16 at 19:09
-
Possible duplicate of [Is it possible to mimic process substitution on msys /mingw (with bash 3.x)](http://stackoverflow.com/questions/20866832/is-it-possible-to-mimic-process-substitution-on-msys-mingw-with-bash-3-x) – P.P Aug 05 '16 at 19:16
-
2@P.P., I'm not really fond of that specific potential dupe, inasmuch as it folds in some misconceptions (among them, that bash 3.x *doesn't* support process substitution; that's a msys restriction, as opposed to a version-based one). – Charles Duffy Aug 05 '16 at 19:22
1 Answers
14
mkfifo foo.fifo
## if your "commands" is multiple commands
# { commands ...; } >foo.fifo &
# otherwise, if it's just one
commands ... >foo.fifo &
something_else foo.fifo
is the closest available equivalent to
something_else <( commands ... )

Charles Duffy
- 280,126
- 43
- 390
- 441
-
Possible "robustness" improvements would be to use something like `mktemp` to generate a directory for one of more pipes safe from collisions (or just to generate a name to use for the pipe, since `mkfifo` is atomic), etc. In reality, that's all `<( ... )` is doing behind the scenes: it's just syntactic sugar for a more robust variant of this answer. – mtraceur Sep 05 '16 at 07:52
-
3@mtraceur, that's what `<( ... )` is doing behind the scenes *on platforms where `/dev/fd` is not available*; it uses `pipe(2)` anonymous descriptor pairs where it is. – Charles Duffy Sep 05 '16 at 18:54
-
-
2There's no POSIX way to do this because POSIX does not define `mktemp`. One either needs to reimplement `mktemp` with using only POSIX shell behavior or have to come up with some kind of hacks. – Mikko Rantalainen Apr 26 '20 at 11:56