Passing a -x parameter 
Author Message
 Passing a -x parameter

Many (good) Unix programs will recognise a -x parameter as a flag
for it to display how it should be used (and perhaps the date/time
it was compiled)
I would like to do this for my awk programs....

I am having a problem with this since the parameter is unavailable
at the BEGIN phase. In the main body it is expecting a filename
and -x is unlikely to exist....

Mark
--
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** Visit our website on http://www.*-*-*.com/ **



Sat, 25 Mar 2000 03:00:00 GMT  
 Passing a -x parameter


% Many (good) Unix programs will recognise a -x parameter as a flag
% for it to display how it should be used (and perhaps the date/time
% it was compiled)
% I would like to do this for my awk programs....
%
% I am having a problem with this since the parameter is unavailable
% at the BEGIN phase.

Can you elaborate on that? This works fine here, using nawk, mawk, and gawk:
 awk 'BEGIN { if (ARGV[1] == "-x") print "you did it right" }' -x
and the following script works
 #!/usr/bin/awk -f
 BEGIN {
   if (ARGV[1] == "-x" || ARGV[1] == "--usage") {
      print "This program simply tests passing -x. That's the only option"
   }
 }

--

Patrick TJ McPhee
East York  Canada



Sun, 26 Mar 2000 03:00:00 GMT  
 Passing a -x parameter

Quote:

>Many (good) Unix programs will recognise a -x parameter as a flag
>for it to display how it should be used (and perhaps the date/time
>it was compiled)
>I would like to do this for my awk programs....

>I am having a problem with this since the parameter is unavailable
>at the BEGIN phase. In the main body it is expecting a filename
>and -x is unlikely to exist....

>Mark

This works in TAWK (which I believe you use?).

katz.awk:

BEGIN {
   for (i in ARGV) print ARGV[i]
   delete ARGV
   }

awk -f katz.awk -x c:\autoexec.bat whatever

will print:

katz.awk
-x
c:\autoexec.bat
whatever

and nothing else is printed.

In your case you would test whether ARGV[i] == "-x" and if so print
the information you want and then delete ARGV[i]. Presumably all the
other parameters in ARGV[] are file names and you will leave them
alone. (Or they are other special strings and you should process them
and then usually delete them. You could also set ARGV{i} = "".)

Also, note the difference between:

for (i in ARGV)...

and

for (i = 1; i <= ARGC; i++) ...

DKM



Sun, 26 Mar 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing a parameter Rexx to JCL and return a parameter to JCL

2. language rules question: using a (passed in) parameter to define a parameter

3. APL+Win and array parameter passing from OCX

4. passing parameter from awk back to korn shell

5. Pass parameter to pattern

6. Parameter passing to a method

7. Pass an AWK variable to a pipeline program as a parameter

8. Passing an array element as a parameter

9. parameter passing from apple script to RB

10. parameter passing with folderitem.launch

11. Passing a parameter to an AppleScript

12. Help passing command line parameters to awk scripts

 

 
Powered by phpBB® Forum Software