Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `ruby -e "$(curl url)"` means?

Tags:

ruby

What does this line from Homebrew mean?

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

I understand -e will include ruby code in command but I don't get the $() part. What's the dollar sign bracket doing here?

And very importantly, where can I find the documentation for this?

like image 254
Henry Yang Avatar asked Jan 02 '23 05:01

Henry Yang


1 Answers

$(...) is Bash command substitution. It happens before the command is executed; it executes the command inside the parentheses and substitutes its output. For example,

echo "There are $(ls | wc -l) files in this directory"

will first execute ls | wc -l which will output e.g. 17; then echo "There are 17 files in this directory".

curl is a command-line utility that fetches the contents at an URL and outputs that content, by default. Thus, /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) will first download the contents of https://raw.githubusercontent.com/Homebrew/install/master/install , then substitute it into the command line as the parameter of the -e option. Ruby will then execute it as Ruby code.

like image 150
Amadan Avatar answered Jan 21 '23 11:01

Amadan