16

Ruby Version Manager (RVM) installed like so:

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

I understand what first < mean (feeds bash script to bash interpreter), I'm confused with <(...) part. So, what parentheses do here and the less than sign. In which cases we can use same syntax?

I tried to dig on the internet, found this SO question https://stackoverflow.com/questions/2188199/bash-double-or-single-bracket-parentheses-curly-braces and this question on ubuntuforums: http://ubuntuforums.org/showthread.php?p=7803008 But still have no idea why we use those parentheses and why we use input redirection twice.

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

ain't the same?

Thanks.

Nemoden
  • 2,437
  • 3
  • 25
  • 30
  • I think the better questions is: Why is this the same `bash <(curl -s ...)` – Bruno Bronosky May 26 '17 at 20:13
  • command <(...) works when the command accepts a filename in that location. If you put another < before it the command has to accept input from stdin. Some commands will work either way and use stdin if there is no filename supplied. The accepted answer hints at this difference. – Lee Meador Jun 08 '18 at 19:10

2 Answers2

11

It's process substitution. It feeds the output of the command into a FIFO that can be read from like a normal file.

Ignacio Vazquez-Abrams
  • 111,361
  • 10
  • 201
  • 247
9

It means "run the command inside the brackets, and return a filename that represents the standard output of that command here".

So, that translates to two commands:

curl ... > something
bash -s stable < something

...where "something" is the magic. (Typically, /dev/fd/... or a pipe.)

Daniel Pittman
  • 3,688
  • 17
  • 15
  • 4
    but why can't I just use curl ... | bash -s stable ? – Lilás Nov 17 '16 at 17:25
  • @Lilás the example I came from wanted to work with a copy/pasted to a while-read. Example: `while read x; do echo "${x}"; done < <(echo "one two three" | tr ' ' '\n')`. More likely if the "one two three" came from a program's stdout, but even then this use is probably rare. It is neat, but esoteric. – Kevin May 31 '20 at 00:20