簡體   English   中英

Ruby Chef OS相關

[英]Ruby chef os related

我需要從數組中刪除制表符空間,並將值與一個帶有字符串的數組值進行比較。

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> 

使用Array#mapString#gsub

因此,代碼將是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM