Ruby executes remote scripts on a single line. (e.g. rvm installation)

install rvm in one example line:

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

Now let's say I have ruby ​​scripts like http://blah.com/helloworld.rb

 puts "what ur name?" name = gets.chomp puts "hello world from web, #{name}" 

I would like to do this in my shell without creating a temporary file on one line or even a better command.

 wget http://blah.com/helloworld.rb; ruby helloworld.rb; rm helloworld.rb 

I tried this, but the user's invitation will be ignored due to an earlier channel.

 curl -s http://blah.com/helloworld.rb | ruby 

What is the correct way to execute a remote ruby ​​script? Thanks!

+4
source share
4 answers

Like this:

 ruby < <(curl -s http://blah.com/helloworld.rb) 

Ruby evaluates ruby ​​code in the same way that bash evaluates shell code

+6
source

Another Ruby option based on installing Caliber for shell scripts:

 ruby -e "require 'open-uri'; system open('http:// or local file').read" 

The same goes for Ruby scripts:

 ruby -e "require 'open-uri'; eval open('http:// or local file').read" 

Edited . Fixed a missing sentence and added ruby ​​script execution

+5
source

From http://brew.sh/ :

 ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" 
+4
source

In your Ruby code, you need to open stdin again and bind it to the control terminal device /dev/tty !

 rubyscript="$( cat <<-'EOF' puts "what ur name?" name = gets.chomp puts "hello world from web, #{name}" EOF )" ruby <(echo '$stdin.reopen(File.open("/dev/tty", "r"))'; echo "$rubyscript") 
0
source

All Articles