35

I've seen that rvm (ruby version manager) is installed using the following command:

bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )

So as I understand we get the script content and pass it to the bash (I believe < < and << is the same thing?) I am interested in the < < part, found following description on the net:

<< token Means use the current input stream as STDIN for the program until token is seen.

This is somehow not clear for me, can someone make an example or explain it in more simple way?

Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233
Stonerain
  • 453

2 Answers2

44

No, < < and << are not the same thing.

The first is composed of the common < redirection character combined with the first character of the <(command) syntax. This is a ksh construct (also found in bash and zsh) known as process substitution that takes the output of command and provides it in a file whose name refers to the other end of the pipe command is writing to.

In other word you can think of < <(command) as < file, where file contains the output of command.

enzotib
  • 51,661
  • 5
    I learnt about this command a few days ago, it's a very useful command. The things which you can do with this are only limited by your imagination: e.g. this command gives you a list of only hidden files : diff <(ls) <(ls -a) – Khaja Minhajuddin Oct 18 '11 at 03:06
  • 2
    This syntax might indeed be quite useful but in Stonerain's specific case, it doesn't seem to provide any added value compared to a simple pipe. – jlliagre Nov 27 '11 at 09:57
  • 1
    In the above syntax it doesn't help. But if you change it slightly, it's much better: bash <(curl ...) instead of bash < <(curl ...) doesn't steal STDIN, so you're free to answer prompts and provide input in the script. – tylerl Dec 21 '11 at 19:23
  • Using <() seems to be a great alternative for sending multiple $variables to commands directly, instead of having to needlessly write the $variables to files first. diff <(echo "$text1") <(echo "$text2") http://stackoverflow.com/questions/13437104/compare-content-of-two-variables-in-bash – Sepero Dec 06 '12 at 16:52
19

It is a convoluted way of doing the simpler:

curl -s https://raw.github.com/... | bash
jlliagre
  • 61,204