6 ms·
-o >(grep O_DIRECT) This is cool. Never seen it (but it makes sense.)
by lelf 7y ago
-o >(grep O_DIRECT)
This is cool. Never seen it (but it makes sense.)
- mmastrac 7y agoIts cousin diff <(cmd a) <(cmd b) is also very handy.
- lostmsu 7y agoNot a command line guru, but this looks interesting. Does it compare outputs of two commands? How does it do it?
- arendtio 7y ago<(command) is being replaced by a path to a file which contains the output of the command: $ ls <(echo A) /dev/fd/63 $ cat <(echo A) A So diff <(command1) <(command2) becomes diff /dev/fd/62 /dev/fd/63
- smartmic 7y agoIt is called process substitution and specific to Bash (not POSIX shell compliant). The output of the commands in parenthesis will become runtime (file) inputs for the diff command. More: https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html https://www.gnu.org/software/bash/manual/html_node/Process-S...
- emmelaich 7y agoIt's not specific to bash -- it's in ksh as well. And zsh. I'm also pretty sure it originated in ksh, not bash.
- hans1729 7y agodiff compares files line by line, here we just redirect the output of cmd1 and cmd2 via <, so they serve as 'proxies' for the file-args diff expects you might want to read into redirection on the commandline, it's amazingly powerful
- mmastrac 7y agoIt might be easiest to view it like so: $ echo <(echo 1) <(echo 2) /dev/fd/63 /dev/fd/62 The shell spawns two commands connected to pipes, then replaces those with a file that represents the other (read) side of that pipe. The command above with >(grep something) does the same thing, just with the other end of a pipe.
- deaddodo 7y agoIt's not actually a pipe. >, < and | are IO redirection commands; but of those only | is a pipe. Pipes specifically "pipe" the STDOUT of one command as the STDIN of another. The other two instead point a command to the file descriptor of the output of another. This is explained in more detail here: https://askubuntu.com/questions/172982/what-is-the-difference-between-redirection-and-pipe https://askubuntu.com/questions/172982/what-is-the-differenc...
- mmastrac 7y agoOn linux at least, these two constructions are effectively identical from the view of the "piped" process. # cat <(ls -l /proc/self/fd/) total 0 lrwx------ 1 root root 64 Jan 12 15:02 0 -> /dev/pts/0 l-wx------ 1 root root 64 Jan 12 15:02 1 -> pipe:[20519634] lrwx------ 1 root root 64 Jan 12 15:02 2 -> /dev/pts/0 lr-x------ 1 root root 64 Jan 12 15:02 3 -> /proc/23611/fd/ # ls -l /proc/self/fd/ | cat - total 0 lrwx------ 1 root root 64 Jan 12 15:02 0 -> /dev/pts/0 l-wx------ 1 root root 64 Jan 12 15:02 1 -> pipe:[20518265] lrwx------ 1 root root 64 Jan 12 15:02 2 -> /dev/pts/0 lr-x------ 1 root root 64 Jan 12 15:02 3 -> /proc/23621/fd/
- sillysaurusx 7y agoThe <(foo | bar) syntax evaluates to a file path, e.g. $ echo <(echo hi) /dev/fd/63 If a program reads from that file path, it gets the output of the command chain. $ cat <( (echo foo; echo bar) | grep bar ) bar Of course, that's a silly example. But that explains how the diff example works, since it's the same idea: diff just reads from the two "files". EDIT: Heh, 5 different replies within the same 60 second window.
- deaddodo 7y agoYes. You're directing the STDOUT of each command as a FILE into diff. Diff takes two files, thus the duplication.
- mijoharas 7y agoit does[0] you are redirecting stdout of both of the subprocesses (the things in brackets) to the stdin of the diff command (I think it creates two different input streams, that diff knows how to compare). [0] http://tldp.org/LDP/abs/html/process-sub.html http://tldp.org/LDP/abs/html/process-sub.html
- kevinmgranger 7y agoIt also has a great unofficial name: the penguin operator. <() See? Penguin!