This is my AWK script
#!/bin/awk -f
(1 == 2)
{
print "OK"
}
And the output is
OK
OK
OK
...
The condition 1==2
is clearly wrong, but the action is executed nonetheless. Why is that?!
Command terminating semi colon is optional in awk if next command starts on a new line.
Here (1 == 2)
is interpreted separately from {...}
block that starts from new line. (1 == 2)
is returning false and nothing is printed but next { ... }
block is considered independent and here OK
is printed for each row.
You should fix it by using:
#!/bin/awk -f
(1 == 2) {
print "OK"
}
Now anything inside { ... }
will be evaluated only when condition succeeds.