Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External variable

Status
Not open for further replies.

biljana

Technical User
Mar 5, 2002
3
CA
Hello,
I have 2 short scripts that suppose to display user defined variable NAME. Script1 works fine, but script2 gives the syntax error. The only difference is space in NAME variable.
I'm running this on dgux R4.20MU06 generic AViiON PentiumPro

#script1
NAME="firstlast"
echo test | awk '{print "'$NAME'" }'

#script2
NAME="first last"
echo test | awk '{print "'$NAME'" }'


script 2 gives the syntax error:

UX:awk: ERROR: syntax error at source line 1
UX:awk: INFO: Context is
{print >>> "first <<<
UX:awk: ERROR: Illegal statement at source line 1
UX:awk: ERROR: Missing }

Thanks a lot
 
I slved the problem,
this works
echo test | awk '{print "'"$NAME"'" }'


 
Instead of [tt]echo test | awk '{print "'"$NAME"'" }'[/tt]
why not use [tt]awk 'BEGIN{print "'"$NAME"'" }'[/tt]?

For an introduction to Awk, see faq271-5564.
 
I agree that 'echo test | awk ....' does not have much sense but the actual script is different. I used it just to simulate the problem and make it short.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top