So when I run this on a mac:
awk 'END { for (name in ENVIRON) {
print "key: "name; }
}' >> app-deployment.yaml
awk just freezes. If I change it to just print to /dev/null
like this
awk 'END { for (name in ENVIRON) {
print "key: "name; }
}' < /dev/null
It works fine. Am I doing something wrong with my redirection? Is there something else I'm doing wrong here?
So in short:
awk 'BEGIN{ action-without-getline }'
: awk exits without processing any input filesawk 'BEGIN{ action-with-getline }'
: awk exits after processing the input filesawk 'END{ action }'
: awk exits after processing the input filesawk 'BEGIN{action}END{ action }'
: awk exits after processing the input filesawk 'BEGIN{action; exit}END{ action }'
: awk exits without processing any input filesBut what if there are no input files specified:
So this just means that
will not hang, but awaits input from
/dev/stdin
Change
END
toBEGIN
to be able to work without any input:OP's Code1 analysis:
Doesn't have any Input_file passed to
awk
andEND
block in anyawk
code requires any Input_file to be passed,it hangs there since it is NOT able to find one.OP's Code2 analysis:
Now you are passing
/dev/null
as an Input toawk
(though it will NOT have any contents to be read byawk
but still it has a Input passed to it), so as per rule once Input_file is done processingEND
block processes, in this case since NO contents are there soEND
section printing of statements should happen.To make
awk
code work without passing anInput_file
way: In case anyone wants toawk
to work withoutInput_file
use onlyBEGIN
section, which as perman awk
page will be executed beforeInput_file
gets processed so even you are NOT passing any Input_file it will NOT wait for its presence and onceBEGIN
section is executed it will come out of program.