【问题标题】:using SCL in the command call for Ruby script在 Ruby 脚本的命令调用中使用 SCL
【发布时间】:2019-02-19 12:48:09
【问题描述】:


我的雇主在 /usr/bin/ruby 中有 Ruby 1.8.7,并且只允许通过 SCL(软件集合)使用 Ruby 2.4。
这意味着当我运行 ruby​​ 时,我需要使用(来自 RH6 shell)scl enablde ruby-24 'ruby foo.rb'foo.rb 是文件名。 我想在第一个执行行上启用 ruby​​ 调用,即,而不是 Ruby 代码文件看起来像:

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

代码看起来

#!cmd
puts "Hello world"

cmd 是通过scl 调用的,并为puts 命令运行Ruby 2.4。我知道可以使用包装文件。我想要 1 个文件中的内容。

【问题讨论】:

    标签: ruby file software-collections


    【解决方案1】:

    这个怎么样:

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

    【讨论】:

      猜你喜欢
      • 2020-02-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多