Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean "bash < <( curl http://rvm.io/releases/rvm-install-head )" [closed]

Tags:

bash

shell

The RVM homepage

http://rvm.io/

recommends people install RVM using

bash < <( curl http://rvm.io/releases/rvm-install-head )

What is this syntax? command <( another_command)

Can't the original line be? curl http://rvm.io/releases/rvm-install-head | bash

like image 902
nonopolarity Avatar asked Nov 04 '10 13:11

nonopolarity


2 Answers

<(command) creates a named pipe with the output of the command (or uses an existing /dev/fd file), and substitutes the filename of that pipe into the command. < then redirects standard input from that given file.

So yes, in this case, this is equivalent to

curl http://rvm.io/releases/rvm-install-head | bash

I'm not sure why they suggest the more complicated and less portable version. In some cases, you would prefer the version using < <() to the version using a pipe, as the pipe creates a subshell for the command receiving input (in this case, bash), while the < <() creates a subshell for the command producing output. If you use a pipe, then the command in the subshell can't modify variables in the shell environment, which is sometimes desired (if you wanted to pipe something to a while read ... command). However, in this case, the output of the command is just being passed directly to an explicit invocation of bash; there is nothing that needs to be run from the parent shell here.

like image 144
Brian Campbell Avatar answered Oct 19 '22 02:10

Brian Campbell


See part 23 of the advanced bash scripting guide.

In short, the effect of the <( x ) and >( y ) syntaxes are the following:

  • You put them in your command line where a filename is expected

  • Enclosed command will either

    • redirect stdout to (<(x)), or
    • read stdin from (>(y))

    a temporary file (or a named pipe, bash will manage it), the name of which will be given to your external command.

like image 25
Benoit Avatar answered Oct 19 '22 02:10

Benoit