greggmi
greggmi

Reputation: 505

AWK: error with variable

I'm writing a bash script and have some variables I want passed into the awk call. The terminal responds with the msg "awk: line 1: syntax error at or near <" I have another variable vary similar to this one, I'm not sure fail this one fails bu the other one is ok

Here is the variable that fails:

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>\
"

here is a sample of variable that passes, the rest is similar:

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>\
"

And here is the call:

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

I know that issue is with the variable not the awk script. I might be missing an escape somewhere, but I can't seem to find one. Can anyone help me figure out the issue?

Upvotes: 0

Views: 105

Answers (1)

William Pursell
William Pursell

Reputation: 212374

You need to use double quotes to protect the variables from expansion by the shell:

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

Upvotes: 1

Related Questions