getopt does not parse optional arguments to parameters

后端 未结 3 1897
感情败类
感情败类 2020-12-01 03:15

In C, getopt_long does not parse the optional arguments to command line parameters parameters.

When I run the program, the optional argument is not recognized like t

3条回答
  •  暖寄归人
    2020-12-01 04:12

    Although not mentioned in glibc documentation or getopt man page, optional arguments to long style command line parameters require 'equals sign' (=). Space separating the optional argument from the parameter does not work.

    An example run with the test code:

    $ ./respond --praise John
    Kudos to John
    $ ./respond --praise=John
    Kudos to John
    $ ./respond --blame John
    You suck !
    $ ./respond --blame=John
    You suck , John!
    

提交回复
热议问题