Ruby主厨os相关

时间:2017-04-12 13:22:16

标签: ruby automation chef

我需要从数组中删除制表符空间,并将值与一个数组值与字符串进行比较。

inspec> command("chage -l root").stdout.split("\n").flatten{|x| x.strip || x}
=> ["Last password change\t\t\t\t\t: Feb 27, 2017",
 "Password expires\t\t\t\t\t: May 28, 2017",
 "Password inactive\t\t\t\t\t: Apr 20, 2067",
 "Account expires\t\t\t\t\t\t: Nov 27, 2019",
 "Minimum number of days between password change\t\t: 0",
 "Maximum number of days between password change\t\t: 90",
 "Number of days of warning before password expires\t: 7"]
inspec> 

1 个答案:

答案 0 :(得分:0)

使用Array#mapString#gsub

所以代码将是:

command("chage -l root").stdout.split("\n").flatten{|x| x.strip || x}.map{|x| x.gsub(/\t/, '')}