【发布时间】:2018-08-02 14:07:38
【问题描述】:
为了检查安装程序是否已安装,我做了:
installer status |grep Version| cut -c12-13
输出 [原文如此] 说:
installer not found
但如果已安装,它会显示 11 或 10(任何数字)。如果输出是<=10 || >=11,那么它会说not installed,然后继续安装。在库中,它给出:
def get_installer_linux_version
begin
cmd = Mixlib::ShellOut.new('installer status |grep Version| cut -c12-13')
cmd.run_command
rescue Errno::ENOENT => e
return '0.0'
end
return 'Version 10' if cmd.stdout.include? '10'
return 'Version 11' if cmd.stdout.include? '11'
end
在安装配方中是:
if get_installer_linux_version.to_i <= 10 || get_installer_linux_version.to_i >= 11
log 'installer is installed'
else
log 'installer is not installed so procceding with the installation'
【问题讨论】:
-
认真的吗?说明该语言的一个基本功能被破坏了,这将导致几乎所有编写的代码都无法工作,而不是接受您自己的代码可能存在缺陷?
get_installer_linux_version.to_i返回什么值? -
你的问题是什么?
-
更不用说您正在将字符串
"version XX"(或nil)与数字进行比较。 -
什么是
ouput? -
get_installer_linux_version.to_i 返回 bash:安装程序:找不到命令
标签: ruby chef-infra