在ruby命令中传递变量?

时间:2017-04-22 02:00:20

标签: ruby linux

prueban8文件内容为:

 $F[1] > "2" and $F[1] < "4" and $F[3] == "pet"   

代码是:

ruby -a -F ';' -ne 'input = File.read("prueban8"); eval (input); puts  $F[2] end' ppp.txt

但我不能传递变量出现错误 ,意外的输入结束

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我用这个解决了

library(XML)

txt='<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <GetListItemsResult>
      <listitems xmlns:s=\'uuid:SBDSHDSH-DSJHD\' xmlns:dt=\'uuid:CSDSJHA-DGGD\' xmlns:rs=\'urn:schemas-microsoft-com:rowset\' xmlns:z=\'#RowsetSchema\'>
        <rs:data ItemCount="2">
          <z:row title="test" port="8080" space=\'100.000\' datecreat=\'2017-04-21 17:29:23\' id=\'1\' />
          <z:row title="apple" port="8700" space=\'108.000\' datecreat=\'2017-04-21 17:29:23\' id=\'2\' />
        </rs:data>
      </listitems>
    </GetListItemsResult>
  </GetListItemsResponse>
 </soap:Body>
</soap:Envelope>'

doc <- xmlParse(txt)

namespaces <- c(z="#RowsetSchema")
df <- XML:::xmlAttrsToDataFrame(getNodeSet(doc, path='//z:row', namespaces))

df
#   title port   space           datecreat id
# 1  test 8080 100.000 2017-04-21 17:29:23  1
# 2 apple 8700 108.000 2017-04-21 17:29:23  2