No. The for(i=0;i<10;i++)
is a classic programming construct (see Traditional for loops) that is present in many languages. It can be broken down to:
start-expression; end-condition; end-of-iteration-expression
In other words, what I wrote above means "initialize i to 0 and, while i is less than 10, do something and then increment i by 1. Yes the syntax is confusing but that's just the way it is. The end-of-iteration-expression
(++x
in this case) is executed once at the end of each loop. It is equivalent to writing:
while(i<10){print i; ++i}
As for the $x
, I believe that just checks that a field of that number exists and that its contents do not evaluate to false (as explained in Mathias's answer below). $N
will return true if the field number N exists and is not a type of false
. For example:
$ echo "a b c d" | awk '($4){print "yes"}'
yes
$ echo "a b c d" | awk '($14){print "yes"}' ## prints nothing, no $14
$ echo "a b c 0" | awk '($4){print "yes"}' ## prints nothing, $4 is 0
As you can see above, the first command prints yes
because there is a $4
. Since there is no $14
, the second prints nothing. So, to get back to your original example:
awk '{for(x=1;$x;x++)print $x}'
___ __ ___
| | |
| | |-----> increment x by 1 at the end of each loop.
| |--------> run the loop as long as there is a field number x
|------------> initialize x to 1