{"id":5079,"date":"2019-09-27T19:15:36","date_gmt":"2019-09-27T11:15:36","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=5079"},"modified":"2019-09-27T19:15:38","modified_gmt":"2019-09-27T11:15:38","slug":"getopt","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/getopt","title":{"rendered":"getopt\u547d\u4ee4 – \u89e3\u6790\u547d\u4ee4\u884c\u9009\u9879"},"content":{"rendered":"\n

getopt\u547d\u4ee4\u7528\u4e8e\u89e3\u6790\u547d\u4ee4\u884c\u9009\u9879\uff0c\u68c0\u6d4b\u7ed9\u5b9a\u7684\u9009\u9879\u662f\u5426\u5408\u6cd5\u3002\u5728\u6b64\u547d\u4ee4\u4e2d\uff0c\u9009\u9879\u90e8\u5206\u4e3b\u8981\u7528\u4e8e\u5f71\u54cdgetopt\u547d\u4ee4\u89e3\u6790\u9009\u9879,\u5176\u4e2doptstring\u662f\u9700\u8981\u89e3\u6790\u7684\u5408\u6cd5\u9009\u9879\u7684\u5b57\u7b26\u4e32\uff0cparamenters\u901a\u5e38\u662f\u4e00\u7ec4\u53d8\u91cf\uff0c\u7528\u4e8e\u5b58\u50a8\u4ece\u547d\u4ee4\u884c\u83b7\u53d6\u7684\u6bcf\u4e2a\u9009\u9879\u53ca\u53c2\u6570\u3002<\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong> getopt [\u53c2\u6570] <\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n
-a<\/td>\u5141\u8bb8\u957f\u9009\u9879\u4ee5\u5355\u4e2a\u5b57\u7b26”-“\u5f00\u59cb<\/td><\/tr>
-n<\/td>\u6307\u5b9a\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u4f9bgetopt(3)\u51fd\u6570\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u65f6\u4f7f\u7528<\/td><\/tr>
-o<\/td>\u8bc6\u522b\u5355\u5b57\u7b26\u7684\u77ed\u9009\u9879<\/td><\/tr>
-q<\/td>\u7981\u6b62\u8f93\u51fa\u9519\u8bef\u4fe1\u606f<\/td><\/tr><\/tbody><\/table>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n

\u68c0\u67e5\u63d0\u4f9b\u7684\u53c2\u6570\u5217\u8868(-a -b test1 -cd test2 test3)\uff0c\u5e76\u57fa\u4e8e\u63d0\u4f9b\u7684optstring\u8fdb\u884c\u89e3\u6790 \uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# getopt ab:cd -a -b test1 -cd test2 test3<\/pre>\n","protected":false},"excerpt":{"rendered":"

getopt\u547d\u4ee4\u7528\u4e8e\u89e3\u6790\u547d\u4ee4\u884c\u9009\u9879\uff0c\u68c0\u6d4b\u7ed9\u5b9a\u7684\u9009\u9879\u662f\u5426\u5408\u6cd5\u3002\u5728\u6b64\u547d\u4ee4\u4e2d\uff0c\u9009\u9879\u90e8\u5206\u4e3b\u8981\u7528\u4e8e\u5f71\u54cdgetopt\u547d\u4ee4\u89e3 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/5079"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=5079"}],"version-history":[{"count":5,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/5079\/revisions"}],"predecessor-version":[{"id":5101,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/5079\/revisions\/5101"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=5079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=5079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=5079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}