Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does anyone know what the "<(" syntax does:

  bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
I couldn't find documentation (hard to search for as you might imagine). Testing it out, basically that line downloads and executes the bash script stored at https://rvm.beginrescueend.com/install/rvm . Would like to understand how it works; is it related to the $(command) expansion construct? Why not use "curl -s http://files.redsymbol.net/foo/foo.sh | bash"?


<() is a new way to do I/O redirection, by which I mean it was introduced by I think the Korn shell in the early 1990s, which explains why you haven't heard of it. Also it isn't implementable on all Unixes.

The way it works is that if you say

    foo <(bar) -o >(baz) <(quuz)
foo sees them as command-line arguments, which might look like

    foo /dev/fd/3 -o /dev/fd/4 /dev/fd/5
and if it is clever enough to treat them as filenames and open them, then it will get the stdout of bar, the stdin of baz, and the stdout of quux, respectively.

The way this works is that the shell opens pipes to the other command lines first, then generates filenames for them.

I did not know that you could use it with other I/O redirections such as <!

As a bonus, the <() syntax means you can pipe even to and from commands that don't read from stdin or stdout. They must not, however, depend on the ability to seek.

My most common use for this is nonlinear pipe flow, e.g.

    diff -u <(sort -u file1) <(sort -u file2)
Hope this helps!


You bet it helps. Thanks for the great explanation!


I think the parentheses are just for grouping of the second command. The "<" means feed the stdout of the second command into the stdin of the first.

So what's happening here is the output of curl (a script) is being fed directly into a bash shell and executed. I think it's basically an awkward way of piping a command in reverse.


I think the parentheses are just for grouping of the second command. The "<" means feed the stdout of the second command into the stdin of the first.

Why are there two "<" then? It seems to be required; when I try something like "bash < (curl -s ...)" it fails with syntax error.


alright, never mind what I said before:

http://tldp.org/LDP/abs/html/process-sub.html

Looks like the equivalent of the "read" example partway down the page. curl is actually being executed in a subshell.


using only the second "<" would result in bash being called with a argument like "/dev/fd/N", which is where the output of the subshell is coming from.

The first "<" redirects the output of this file descriptor into the stdin of bash.

So both are needed, but you could just do it with a pipe :/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: