灵感来自this我现在
hostname = %x{hostname}
if ['staging', 'prod', 'jlpc'].include? hostname
puts "yes"
end
我的Linux主机名为jlpc
但不打印yes
。
为什么这不起作用?
答案 0 :(得分:5)
%x{hostname}
# => "hostname\n"
解决方案:
puts "yes" if ['staging', 'prod', 'jlpc'].include? hostname.chomp
答案 1 :(得分:3)
我在我的机器上试过,该行在我的主机名末尾添加\n
。所以,试试
hostname = %x{hostname}.rstrip