gawk: fatal: `variable used on command line with back slashes' is not a legal variable name

Under some odd circumstances setting up a gawk variable with a value via the Linux command line can give rise to fatal error messages like:
gawk: fatal: `\p\P\o\p\S\i\z\e\' is not a legal variable name
This may occur with gawk --version GNU Awk 3.1.5 but the circumstances are obscure. In once example, the command line worked on one system but failed on another with a similar but not identical version of the Linux operating system and T-shell.

Failing system

uname -a
Linux 2.6.18-308.13.1.el5 #1 SMP Tue Aug 21 17:10:18 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

Ok system

uname -a
Linux 2.6.18-308.24.1.el5 #1 SMP Tue Dec 4 17:43:34 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

Work Around

In this case the error was reported for the first gawk variable initialised by the command line and gawk should have read three inputs. The first of these was a simple file but the other two used shell environment variables to specify the files to be read and the second also used tcsh wild cards (???). Even though only one file matched the wild cards in the second input, gawk complained about its first -v variable name.

When ??? was removed and the file name was used gawk worked as expected. (The shell environment variables were not changed.)

I.e. replaced $POPDIR/pop.??? with $POPDIR/pop.000

Where the wild cards may match multiple files, (as in this case) the file matching can be done by the shell before invoking gawk. E.g.

cat $POPDIR/pop.??? >! /tmp/allpops_$CPU

time \
gawk -f mutation.awk -f mutation_define.awk -v "seed=1$3"		\
     -v "pPopSize=$mutants" -v "nCross=$mutants"\
     -v    "logfile=$POPDIR/pop.$1_parents"	\
     lines_used.dat /tmp/allpops_$CPU $POPDIR/pop.$1_select	\
     >! $POPDIR/pop.$2
if($status) exit $status;


W.B.Langdon 1 September 2013