Re: awk behaviour?

From: Warner Losh <imp_at_bsdimp.com>
Date: Wed, 28 Jul 2021 17:36:33 UTC
On Wed, Jul 28, 2021 at 11:31 AM Michael Butler via freebsd-current <
freebsd-current@freebsd.org> wrote:

> I tripped over this while trying to build a local release ..
>
> imb@toshi:/home/imb> pkg --version | awk -F. '{print $$1 * 10000 + $$2 *
> 100 + $$3}'
> 10001
>
> imb@toshi:/home/imb> pkg --version
> 1.17.1
>
> Is this expected?
>

Why $$ instead of $? $ isn't expanded in '' expressions, so doubling isn't
necessary
unlike in make... With single quotes it works for me:

% pkg --version | awk -F. '{print $1 * 10000 + $2 * 100 + $3}'
11603
% pkg --version
1.16.3

In awk $$n is $($n), so $$ in this context would evaluate $1 to 1 and then
$1 to be 1. And then $2 to be 16
and then $17 to be 0 and then $3 to be 1 and then $1 to be 1 which leads to
10001.

Warner