Expanding wildcard options to main()

Doug Gwyn gwyn at smoke.brl.mil
Wed Apr 3 10:26:30 AEST 1991


In article <1991Apr1.194817.20469 at fmrco> harold at fmrco (Harold Naparst) writes:
>How do you pass wildcard options to a program and get the
>program to expand them like ls does.  Example: suppose I 
>have two files called foo1 and foo2, and I want to run
>myprog on them.  How would I write myprog so that I could
>just do this:
>   % myprog foo*

You should have learned from your UNIX tutorial that wildcards
are expanded by the shell (command language interpreter) before
the commands are run, and the commands receive the expanded SET
of arguments.  Type "echo foo*" to see it in action (assuming
that you do have files "foo1" and "foo2" present).  Program
arguments are passed to C programs as an array of string pointers
as the second argument to the main() function, and to Bourne
shell scripts as "dollar" variables: $1, $2, ...  There is also
an indication of the number of arguments.  Any book on UNIX
programming should explain how to parse arguments.



More information about the Comp.unix.questions mailing list