#! command arguments
David J. Camp
david at wubios.wustl.edu
Sat Sep 30 19:49:56 AEST 1989
I am thinking about implementing a script that can be invoked via the #!
syntax on the first line of a script. I want it to parse any arguments
on that same line, if present, in addition to the arguments on the
invoking command line. I have been experimenting with a simple C
program that prints out its arguments. It seems that if no arguments
are present, the argv[0] is the shell, and argv[1] is the script. If
arguments are present, then argv[0] is still the shell, but argv[1] is
the entire argument list and argv[2] is the script.
What I want to know is, what is the easiest way to determine if
arguments are present. Since other arguments may follow from the
original command line, the argc variable is not sufficient information.
Since I do not know in advance what the name of the script is, I cannot
compare it against a list of known scripts. Assuming free-form
arguments, some of which may be filenames, I cannot simply look for a
'-' character, although that may be what I require if a better
alternative is not presented.
Any help will be appreciated, and please reply directly to me. Thank
you, -David-
#include <stdio.h>
#include <string.h>
void main (argc, argv)
int argc;
char * argv [];
{
int arg;
for (arg = 0; arg < argc; arg++)
{
fprintf (stderr, "argv [%d] = %s\n", arg, argv [arg]);
}
}
--
Bitnet: david at wubios.wustl ^ Mr. David J. Camp
Internet: david%wubios at wucs1.wustl.edu < * > Box 8067, Biostatistics
uucp: uunet!wucs1!wubios!david v 660 South Euclid
Washington University (314) 36-23635 Saint Louis, MO 63110
More information about the Comp.unix.wizards
mailing list