From: Ryan Victory Date: 2013-01-16T23:46:02+09:00 Subject: Re: Variable empty or not nil != "" Your command will always return something, even if it's just an empty string. Replace the check to nil with "" and it should work. Also, two tips: 1. Don't use $variable variable names unless you absolutely need to, these are global and make Ruby look like Perl. Also don 't start a variable name with a capital letter, this denotes a constant. I'd rename your $Fw_Ip variable to fw_ip 2. If you wanted to check for nil, I'd highly recommend the much cleaner looking "variable.nil?" syntax, which is also more ruby-esque. Hope this helps, Ryan On 1/16/13 7:19 AM, fox foxmaster wrote: > Hi all, > > I am doing some evaluating on a variable, > $Fw_Ip = %x[/usr/bin/plink -pw xxxxxx xxxx@xxxxxx "command" |grep > INACTIVE] > > Now I want to do something depending on if the $Fw_Ip is empty or not. > > if ($Fw_Ip != nil) > puts "Active" > else > puts "Inactive" > end > > I guess that the variable is not empty so it will always return True but > if I puts $Fw_Ip it is empty. > > Suggestions on how to solve it would be much appreciated. >