This is driving me insane. All I want to do is pass a command to the terminal from awk, where the command is a string concatenated together made from other variables.
The documentation for awk says that something like
"echo" $1 | getline var
should put the value of $1 into var. But this is not the case. What am I missing here?
I should add that I actually have a loop
for ( i = 1; i <=NF ; i=i+1 )
{
"echo" $i | getline var
printf var " "
}
printf "\n"
for inputfile like
0 2
1 2
outputs
0 0
0 0
what the hell.
Well, it turns out its not a bug.
Whats going on is the getline opens a new file, and depending on your system settings you can only have X files open per program. Once you max out open files, getline can't open any new fd's. The solution is you have to call
for ( i = 1; i <=NF ; i=i+1 )
{
command="echo" $i
command | getline var
close(command)
printf var " "
}
printf "\n"
Certainly this is a subtle point and there should be huge warning signs in the documentation about this! Anyways, I'm just glad I solved it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With