Bash << (curl -s https://rvm.io/install/rvm): what does it do?

Possible duplicate:
What does it mean "bash <(lt; ltl (curl rvm.io/releases/rvm-install-head)"

I am working on installing Ruby on Rails on a Mac OS X lion and stumbled upon a few tutorials that caused this line:

 bash < <(curl -s https://rvm.io/install/rvm) 

I don’t know what the bash < < bit is for.

What does this line do?

thanks

+4
source share
4 answers

The first < redirects the file on the right side to the stdin command on the left.

The syntax <(...) executes the specified command, saving its output to the named pipe (a special kind of file that outputs everything written to it without saving it to disk) and replaces the integer <(...) with the file name. This is called a process replacement (you can find it in man bash ) and it is used whenever a file is required, but you want to use the output of the command.

As for curl , this is a command that loads the URL specified as an argument and displays it ( stdout ).

In short , what the command you gave is:

  • Starts bash, exposing it as input to a temporary named pipe.
  • Loads the URL https://rvm.io/install/rvm , which is a bash script, and saves it into a temporary named pipe, specified as input to bash.

This effectively runs a script by URL with bash.

+6
source

The <(command) syntax is used to perform process substitution. Read more about this here: http://tldp.org/LDP/abs/html/process-sub.html

This is very useful if you want the output of one command to be passed as a file argument to another command. The <(command) syntax concludes as if it were a file.

For example, we know that perl requires a perl program as an argument.

Now, if the perl program is in the URL, http://pastebin.com/raw.php?i=wdtZYvvr , we know that the output of curl http://pastebin.com/raw.php?i=wdtZYvvr will be the program in this url. Thus, we can provide the output of this command as a perl argument as follows:

 perl <(curl http://pastebin.com/raw.php?i=wdtZYvvr) 

I often find replacing a process very useful when I want to use the output difference of two commands, not two files. But diff requires two file arguments. So, we deliver two outputs as files in diff, using process substitution.

+3
source

The bash < < bit is essentially an instruction for interpreting the output of a curl command as command line commands, and curl is just browsing a web page. If you open https://rvm.io/install/rvm , you will see a script prompting you to run bash.

0
source

Many shells, including bash, use < to redirect input. foo << <(bar) means that foo will read the output of the string as input.

0
source

Source: https://habr.com/ru/post/1392789/


All Articles