0

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?

2
  • 2
    Use quotes: -v insert="$helpInsert" Commented Mar 29, 2013 at 15:03
  • @WilliamPursell Geez I knew it would something simple. Can you put this as an answer so I can say the question has been answered Commented Mar 29, 2013 at 15:07

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.