[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Is there a way to assign to a hash via the -v option
From: |
arnold |
Subject: |
Re: [bug-gawk] Is there a way to assign to a hash via the -v option |
Date: |
Mon, 07 Mar 2016 08:40:19 -0700 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Peng Yu <address@hidden> wrote:
> > David's suggestion is one option. Another is simply to mix the -e and -f
> > command line options and do the assignment in a BEGIN rule suppplied
> > on the command line.
>
> Can you provide an example for the above one?
Here you go, shell quoting tricks included:
$ cat test.awk
BEGIN { print x[1], x[2] }
$ x1="this is x1" x2="this is x2"
$ cat test.awk
BEGIN { print x[1], x[2] }
$ gawk -e 'BEGIN { x[1] = "'"$x1"'" ; x[2] = "'"$x2"'" }' -f test.awk
this is x1 this is x2
Arnold