0
I have a simple awk script, test1.awk
:
{
x=temp;
print x;
}
When I run it from the Command Prompt with:
awk -v temp=hello -f test1.awk
I get just a cursor. I hit Enter, it writes “hello” and gives another cursor, hit Enter again and it writes “hello” again, etc. Just goes in an endless loop requiring input from the user, and never comes back to the command prompt.
D:\>awk -v temp=hello -f test1.awk
hello
hello
hello
hello
^C
D:\>
How do I get it write “hello” (without requiring user input) and then stop?
Your example is simultaneously complex and trivial. It is complex in the sense that it has a variable that must be set via
-v
, or else the program won’t do anything, and then it copies that variable to another variable for no real functional purpose. It is trivial in the sense that it does nothing but print the value of that variable. When you’re debugging / troubleshooting, trivial is good and complex is bad. For trying to get something (anything) to work, you should probably start with trivial things like{ print "Hello"; }
. For a slightly less trivial example, see my answer. – Scott – 2018-10-27T02:26:48.170