How would getopt
know where your -o
options end, and where your command arguments
start?
One simple workaround is to use to -o
specifiers:
$ cat t.c
#include
#include
int main(int argc, char **argv)
{
char op;
while ((op = getopt(argc, argv, "o:")) != EOF) {
switch (op) {
case 'o':
printf("Option: %s\n", optarg);
break;
default:
break;
}
}
}
$ gcc t.c
$ ./a.out -o one -o two -o three
Option: one
Option: two
Option: three