简体   繁体   English

在Ruby脚本的命令调用中使用SCL

[英]using SCL in the command call for Ruby script


My employer has Ruby 1.8.7 in the /usr/bin/ruby, and allows the usage of Ruby 2.4 only via SCL (sofoware collections). 我的雇主在/ usr / bin / ruby​​中拥有Ruby 1.8.7,并且仅允许通过SCL(软件集合)使用Ruby 2.4。
Which means that when I run ruby, I need to use (from the RH6 shell) scl enablde ruby-24 'ruby foo.rb' when foo.rb is the file name. 这意味着当我运行ruby时,当foo.rb是文件名时,需要使用scl enablde ruby-24 'ruby foo.rb' I want to enable the ruby call on the first execution line, ie, instead of the Ruby code file looking like: 我想在第一个执行行上启用ruby调用,即,而不是如下所示的Ruby代码文件:

#!/usr/bin/ruby
puts "Hello world"

That the code will look 该代码将看起来

#!cmd
puts "Hello world"

Where the cmd is what calls via the scl and run the Ruby 2.4 for the puts command. cmd是通过scl调用并为puts命令运行Ruby 2.4的地方。 I know that a wrapper file can be used. 我知道可以使用包装文件。 I want something in 1 file. 我想要一份文件。

How about this: 这个怎么样:

#!/usr/bin/ruby
if RUBY_VERSION != "2.4.1"
  exec "scl enable ruby-24; ruby __FILE__"
end
puts "Ruby Version: #{RUBY_VERSION}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM