2013-03-29 37 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