Named Pipes in Bash
hollenback.net
hollenback.net
$ mkfifo ~/pipe
$ ./background.sh > ~/pipe &
$ tail -f ~/pipe
http://www.linuxjournal.com/article/2156So I am glad that what OP wrote exists.
Here's what the man page says:
Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of
naming open files. It takes the form of <(list) or >(list). The process list is run with its input or
output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to
the current command as the result of the expansion. If the >(list) form is used, writing to the file
will provide input for list. If the <(list) form is used, the file passed as an argument should be read
to obtain the output of list.
So it's done with /dev/fd if that's available, which basically means Linux with that filesystem mounted. Otherwise it falls back on named pipes.If if a command, for example, needs to do 2 passes, it'll will either have to be 'smart' enough to stick the output in a buffer or fail.
vimdiff =(ls /bin) =(ls /usr/bin)
You can use it even from bash:
zsh -c 'vimdiff =(ls /bin) =(ls /usr/bin)'
vimdiff <(ls /bin) <(ls /usr/bin)< greybot> The infamous "Advanced" Bash Scripting Guide should be avoided unless you know how to filter out the junk. It will teach you to write bugs, not scripts. In that light, the BashGuide was written: http://mywiki.wooledge.org/BashGuide
They felt strongly enough to learn their bot of it. Keep this in mind, I haven't read much of either resource yet.
echo <(true)We really need to refactor our terminology. :)
Related: anybody has ideas to achieve the following?
display the stdout of a program on the console and also write a gzipped version of stdout to a file.
I currently jump through some hoops (involving two term windows) to achieve. 'tee -a' to a named pipe in one window and in another window, 'gzip <' from that named pipe. Would prefer a single-window, single-command solution.
cmd | tee >( gzip - > cmd.out.gz )PS: 'inevitable', you made the same suggestion. But you seem to be hellbanned.
ls -al | tee >(cat) | gzip -c cat /proc/`pidof program`/fd/2
That, of course, won't eliminate the need for a second terminal.(change to your needs, stdin==1, stdout==2, stderr=3)
# define a function that echoes it's first argument:
$ arg1() { echo $1 ; }
$ arg1 test
test
$ arg1 <(echo hello)
/dev/fd/63 echo <(:) :
Null command.
No effect; the command does nothing.
Exit Status:
Always succeeds.