使用 getopt 时,是否有另一种方法可以将两个参数作为单个字符串传递给选项?通常我会做以下事情:
./command -o "key value" [command arguments]
然后我将不得不明确拆分参数字符串
while ((op = getopt(argc, argv, "o:")) != EOF) {
switch (op) {
case 'o':
char* result = NULL;
result = strtok_r(optarg," ");
while(result) {
/* DO STUFF */
result = strtok(NULL," ");
}
break;
default:
printUsage()
break;
}
所以,我想知道是否可以执行以下操作:
./command -o key value [command arguments]
使 getopt 将“值”视为 -o 第二个参数而不是命令参数。