7

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?

2
  • 6
    As a sidenote, pasting in commands that download then execute untrusted scripts off the internet is bad practise. Commented May 30, 2012 at 7:04
  • 2
    @donothingsuccessfully That was my first thought as well. I wonder, if the author wrote about the security implications, e.g. if beginrescueend.com falls into the hand of a domain grabber ~ 10 years in the future. He should have.
    – Residuum
    Commented May 30, 2012 at 12:27

2 Answers 2

11

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
4

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

4
  • Using pipe | is more familiar to me. Why did he use the weird syntax. Is using that a trend?
    – Benjamin
    Commented May 30, 2012 at 2:19
  • One more thing. How do you pronounce << operator? Is it called pipe either?
    – Benjamin
    Commented May 30, 2012 at 2:21
  • 3
    @Benjamin << 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.) Commented May 30, 2012 at 23:10
  • @Gilles. wow. unexpected comment. that's a good point. thank you.
    – Benjamin
    Commented May 31, 2012 at 2:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .