2013-03-29 73 views
0

我正在写一个bash脚本,并有一些变量我想传入awk调用。终端用msg“awk:line 1:语法错误在<处或附近”做出响应“我有另一个变量类似于这个变量,我不确定失败这一个失败bu另一个是好的AWK:错误与变量

这里是失败的变量:这里

helpInsert="\ 
\t<help name=\"vsss.status\"><![CDATA[Displays the active configuration.]]></help>\n\ 
\t<help name=\"vsss.general\"><![CDATA[Allows configuration of general video server parameters. <br />\n\ 
\t\tPressing restore defaults will reset the working configuration, but will not affect the active configuration. <br />\n\ 
\t\tPressing activate will make your working configuration into the active configuration. ]]></help>\n\ 
\t<help name=\"vsss.conf2\"><![CDATA[Allows editing of the working configuration. <br />\n\ 
\t\tSettings are not saved unless submit button is pressed]]></help>\ 
" 

是通过变量的样本,其余的是相似的:

menuInsert="\ 
\t<subpageLvl1>\n\ 
\t\t<name>VSSS</name>\n\ 
\t\t<php></php>\n\ 
\t\t<login>0</login>\n\ 
\t\t<subpagesLvl2>\n\ 
\t\t\t<subpageLvl2>\n\ 
\t\t\t\t<name>Status</name>\n\ 
\t\t\t\t<php>vsss.status</php>\n\ 
\t\t\t\t<xml>vsss.xml</xml>\n\ 
\t\t\t\t<xsd>vsss.xsd</xsd>\n\ 
\t\t\t\t<login>0</login>\n\ 
\t\t\t</subpageLvl2>\n\ 
\t</subpageLvl1>\ 
" 

这里是电话:

awk -v appName=$appName -v insert=$helpInsert 'awk script here' filename 

我知道问题与变量不是awk脚本。我可能错过了某处的逃生,但我似乎无法找到一个。任何人都可以帮我弄清楚这个问题吗?

+2

使用引号:'-v插入=“$ helpInsert”' –

+0

@WilliamPursell吉兹我知道它会简单的东西。你可以把这个作为答案,所以我可以说这个问题已经得到解答 – xsdf

回答

1

您需要通过shell来使用双引号来保护变量从扩展:

awk -v appName="$appName" -v insert="$helpInsert" 'awk script here' filename