In a rails book, the author wrote the script to install ruby rvm.
bash <<(curl -s https://rvm.beginrescueend.com/install/rvm)
But I don't understand how it works. Could you explain this?
In a rails book, the author wrote the script to install ruby rvm.
bash <<(curl -s https://rvm.beginrescueend.com/install/rvm)
But I don't understand how it works. Could you explain this?
There is a << operator (here document) but it is not what is used here.
You have first an input redirection < which says pick the input from the following argument then there is the <(command) known as process substitution which says replace that by a file descriptor containing the output of the command.
This command could have been written
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
but is just a convoluted way of doing:
curl -s https://rvm.beginrescueend.com/install/rvm | bash
one <<(two) runs the command two and pipes its output into one. The more common way of writing it is two | one, so your command can also be written:
curl -s https://rvm.beginrescueend.com/install/rvm | bash
That link is broken now, but the website says to use this instead:
curl -L get.rvm.io | bash -s stable
curl outputs what it downloads, so this downloads the file at get.rvm.io and pipes its contents to bash. If you just run the curl command by itself you can see its a bash script that downloads and installs rvm
| is more familiar to me. Why did he use the weird syntax. Is using that a trend?
pipe either?
<< is the here document operator. foo < <(bar) is mostly equivalent to bar | foo, but with a few differences that don't matter here: mainly, with < <(…), foo executes in the main shell environment, and the command returns when foo returns, whereas with a pipe, foo executes in a subshell and the pipeline waits for both commands to complete. (That's in bash, the behavior is closer in ksh and zsh.)