Re: awk behaviour?

From: Michael Gmelin <freebsd_at_grem.de>
Date: Wed, 28 Jul 2021 19:43:40 +0200
On Wed, 28 Jul 2021 13:29:20 -0400
Michael Butler via freebsd-current <freebsd-current_at_freebsd.org> wrote:

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

Yes, as you're using $$ instead of $.

With single dollar sign you'll get the expected value of:

11701

With double dollar you reference the content of the field, so in case
of 1.17.1:

$$1 * 10000 + $$2 * 100 + $$3

is equal to

$1 * 10000 + $17 + $1

Which is:
10000 + 0 + 1

Which equals

10001

-m


> 
> 	imb



-- 
Michael Gmelin
Received on Wed Jul 28 2021 - 17:43:40 UTC

Original text of this message