These should do the same thing, but...what's going on in the second example? Turns out that the culprit is the seemingly innocuous string concatenation:

print msg ++count

Believe it or not, that is parsed by awk as

print (msg++) count

Obviously, "msg" is a string, so to apply the postincrement operator it must be converted to a number, and that number is 0. "count" is not touched at all; to awk, it's still in the default state (dual empty string/numeric 0; in string context like here, the empty string value is used). The concatenation of 0 with an empty string gives 0, which is the result we see.

But...but...why the does the first version with the literal string work then? Simple: because a literal string can't be postincremented, so the "++" is parsed as preincrement for "count". (Well, simple, yes, even obvious, once somebody tells you.)

So here's the test case again:

$ awk 'BEGIN{ msg = "Hello "; print msg ++count }'
0

This is purposely exaggerated to show that the amount of spaces before the "++" is completely irrelevant; it will still be applied to "msg". As I've been reminded, the awk grammar states that "A <blank> shall have no effect, except to delimit lexical tokens or within STRING or ERE tokens", which is exactly the point.

It's not difficult to make up other cases involving string concatenation where the results differ from what one may expect.

Now it should be apparent that the problem is not something that is likely happen all the time; in fact, depending on the programmer's coding style, the specific task to be solved, and other elements, it may even remain unknown to many and never show up. But when one happens to trigger it, it may be difficult to understand what's going on.