gawk: Ignoring Assigns

1 
1 10.3.5 Treating Assignments as File names
1 -----------------------------------------
1 
1 Occasionally, you might not want 'awk' to process command-line variable
1 assignments (⇒Assignment Options).  In particular, if you have a
1 file name that contains an '=' character, 'awk' treats the file name as
1 an assignment and does not process it.
1 
1    Some users have suggested an additional command-line option for
1 'gawk' to disable command-line assignments.  However, some simple
1 programming with a library file does the trick:
1 
1      # noassign.awk --- library file to avoid the need for a
1      # special option that disables command-line assignments
1 
1      function disable_assigns(argc, argv,    i)
1      {
1          for (i = 1; i < argc; i++)
1              if (argv[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/)
1                  argv[i] = ("./" argv[i])
1      }
1 
1      BEGIN {
1          if (No_command_assign)
1              disable_assigns(ARGC, ARGV)
1      }
1 
1    You then run your program this way:
1 
1      awk -v No_command_assign=1 -f noassign.awk -f yourprog.awk *
1 
1    The function works by looping through the arguments.  It prepends
1 './' to any argument that matches the form of a variable assignment,
1 turning that argument into a file name.
1 
1    The use of 'No_command_assign' allows you to disable command-line
1 assignments at invocation time, by giving the variable a true value.
1 When not set, it is initially zero (i.e., false), so the command-line
1 arguments are left alone.
1