1

Inspired by this I now do

hostname = %x{hostname}

if ['staging', 'prod', 'jlpc'].include? hostname
  puts "yes"
end

My Linux hostname is jlpc but it doesn't print out yes.

Why doesn't this work?

Community
  • 1
  • 1
Jasmine Lognnes
  • 6,597
  • 9
  • 38
  • 58

2 Answers2

5
%x{hostname}
# => "hostname\n"

Solution:

puts "yes" if ['staging', 'prod', 'jlpc'].include? hostname.chomp
sugaryourcoffee
  • 879
  • 8
  • 14
3

I tried on my machine and that line appends a \n at the end of my hostname. So, try

hostname = %x{hostname}.rstrip
Ursus
  • 29,643
  • 3
  • 33
  • 50
  • While not wrong, `chomp` is the conventional method here. A hostname should not have spaces in it. – tadman Aug 19 '16 at 16:08