Copyright (C) 2000-2012 |
GNU Info (gawk.info)Ignoring AssignsTreating Assignments as File Names ---------------------------------- Occasionally, you might not want `awk' to process command-line variable assignments (*note Assigning Variables on the Command Line: Assignment Options.). In particular, if you have file names that contain an `=' character, `awk' treats the file name as an assignment, and does not process it. Some users have suggested an additional command-line option for `gawk' to disable command-line assignments. However, some simple programming with a library file does the trick: # noassign.awk --- library file to avoid the need for a # special option that disables command-line assignments function disable_assigns(argc, argv, i) { for (i = 1; i < argc; i++) if (argv[i] ~ /^[A-Za-z_][A-Za-z_0-9]*=.*/) argv[i] = ("./" argv[i]) } BEGIN { if (No_command_assign) disable_assigns(ARGC, ARGV) } You then run your program this way: awk -v No_command_assign=1 -f noassign.awk -f yourprog.awk * The function works by looping through the arguments. It prepends `./' to any argument that matches the form of a variable assignment, turning that argument into a file name. The use of `No_command_assign' allows you to disable command-line assignments at invocation time, by giving the variable a true value. When not set, it is initially zero (i.e., false), so the command-line arguments are left alone. automatically generated by info2www version 1.2.2.9 |