开发者

ruby executing remote scripts in one line. (like installing rvm)

开发者 https://www.devze.com 2023-03-18 04:43 出处:网络
install rvm in one line example: user$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

install rvm in one line example:

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

Now, say I have a ruby scripts like this at http://blah.com/helloworld.rb

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

I would like to achieve this it in my shell without creating a temp file in one line or even better one command.

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

I have tried this, but user prompt will be ignored because of earlier pipe.

curl 开发者_如何学C-s http://blah.com/helloworld.rb | ruby

What's the correct way to executing a remote ruby script? Thanks!


Like this:

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

Ruby evaluates ruby code similarly to how bash evaluates shell code


Another Ruby option based on Calibre install for shell scripts:

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

The same for Ruby scripts:

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

Edited: Fixed missing quote and added Ruby script execution


From http://brew.sh/:

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


In your Ruby code, you have to reopen stdin and tie it to the controlling terminal device /dev/tty!

rubyscript="$( cat <<-'EOF'
puts "what's ur name?"
name = gets.chomp
puts "hello world from web, #{name}"
EOF
)"

ruby <(echo '$stdin.reopen(File.open("/dev/tty", "r"))'; echo "$rubyscript")
0

精彩评论

暂无评论...
验证码 换一张
取 消