Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
6  
As a sidenote, pasting in commands that download then execute untrusted scripts off the internet is bad practise. –  donothingsuccessfully May 30 '12 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 May 30 '12 at 12:27

2 Answers 2

up vote 11 down vote accepted

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
share|improve this answer

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.