Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the `< <()` syntax?

Tags:

bash

shell

I've been using RVM for a while, and every time I just copied and pasted the following command to get it setup:

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

It bugs me that I don't fully understand the syntax, and why we need the double <, and the parentheses. Can some one explain this or point me to the right reference?

like image 824
Alex Le Avatar asked May 19 '11 20:05

Alex Le


2 Answers

The first one is input redirection. It feeds the contents of a file into the program as input. The second construct is <() and it's process redirection: it treats output of a process like a file. In this case, the effect is that you will run the contents of that url as though it was a bash script -- very dangerous! If you don't trust to source completely, don't do that. An attacker could use this method to have you run commands that would compromise your system.

like image 87
Daenyth Avatar answered Oct 07 '22 08:10

Daenyth


Just my 2 cents. Bashs structure <() as @Daenyth stated "treats output of a process like a file". This structure may be very useful. Just consider following:

 diff <(ls dir1) <(ls dir2)

This will use vimdiff to show differences between contents of dir1 and dir2. Using vimdiff instead diff will even cooler.

like image 42
dimba Avatar answered Oct 07 '22 09:10

dimba