{"id":52258,"date":"2024-12-03T13:21:15","date_gmt":"2024-12-03T05:21:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52258\/"},"modified":"2024-12-03T13:21:15","modified_gmt":"2024-12-03T05:21:15","slug":"linux%e6%96%87%e6%a1%a3%e4%b8%adoption%e6%8c%87%e7%9a%84%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52258\/","title":{"rendered":"linux\u6587\u6863\u4e2doption\u6307\u7684\u662f\u4ec0\u4e48"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>linux\u6587\u6863\u4e2doption\u6307\u7684\u662f\u4ec0\u4e48<\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300alinux\u6587\u6863\u4e2doption\u6307\u7684\u662f\u4ec0\u4e48\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u7c73\u4e91\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<\/p>\n<blockquote>\n<p>\u5728linux\u4e2d\uff0coption\u662f\u6307\u547d\u4ee4\u9009\u9879\uff0c\u662f\u8c03\u6574\u547d\u4ee4\u6267\u884c\u884c\u4e3a\u7684\u5f00\u5173\uff0c\u5373\u9009\u9879\u4e0d\u540c\u51b3\u5b9a\u4e86\u547d\u4ee4\u7684\u663e\u793a\u7ed3\u679c\u4e0d\u540c\u3002option\uff08\u9009\u9879\uff09\u5206\u4e3a\u957f\u9009\u9879\u548c\u77ed\u9009\u9879\uff1a1\u3001\u77ed\u9009\u9879\u90fd\u662f\u4f7f\u7528\u201c-\u201d\u5f15\u5bfc\uff0c\u5f53\u6709\u591a\u4e2a\u77ed\u9009\u9879\u65f6\uff0c\u5404\u9009\u9879\u4e4b\u95f4\u4f7f\u7528\u7a7a\u683c\u9694\u5f00\uff1b2\u3001\u957f\u9009\u9879\u90fd\u662f\u5b8c\u6574\u7684\u5355\u8bcd\uff0c\u4e14\u901a\u5e38\u4e0d\u80fd\u7ec4\u5408\u3002<\/p>\n<\/blockquote>\n<h3><strong>Linux\u4e2d\u547d\u4ee4\u9009\u9879\uff08option\uff09\u53ca\u53c2\u6570\u7b80\u4ecb<\/strong><\/h3>\n<p>\u767b\u5f55Linux\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728#\u6216$\u7b26\u540e\u9762\u53bb\u8f93\u5165\u547d\u4ee4\uff0c\u6709\u7684\u65f6\u5019\u547d\u4ee4\u540e\u9762\u8fd8\u4f1a\u8ddf\u7740\u201c\u9009\u9879\u201d\uff08\u82f1\u6587options\uff09\u6216\u201c\u53c2\u6570\u201d\uff08\u82f1\u6587arguments\uff09\u3002\u5373Linux\u4e2d\u547d\u4ee4\u683c\u5f0f\u4e3a\uff1a<\/p>\n<p><code><strong>command [options] [arguments]<\/strong><\/code><strong> <\/strong>\/\/\u4e2d\u62ec\u53f7\u4ee3\u8868\u662f\u53ef\u9009\u7684\uff0c\u5373\u6709\u4e9b\u547d\u4ee4\u4e0d\u9700\u8981\u9009\u9879\u4e5f\u4e0d\u9700\u8981\u53c2\u6570\uff0c\u4f46\u6709\u7684\u547d\u4ee4\u5728\u8fd0\u884c\u65f6\u9700\u8981\u591a\u4e2a\u9009\u9879\u6216\u53c2\u6570\u3002<\/p>\n<p><strong>\u9009\u9879options<\/strong><strong>\uff1a<\/strong><\/p>\n<p>\u9009\u9879\u662f\u8c03\u6574\u547d\u4ee4\u6267\u884c\u884c\u4e3a\u7684\u5f00\u5173\uff0c\u5373\uff0c\u9009\u9879\u4e0d\u540c\u51b3\u5b9a\u4e86\u547d\u4ee4\u7684\u663e\u793a\u7ed3\u679c\u4e0d\u540c\u3002<\/p>\n<p><strong>\u9009\u9879\u5206\u4e3a\u957f\u9009\u9879\u548c\u77ed\u9009\u9879\u3002<\/strong><\/p>\n<p><strong>\u77ed\u9009\u9879\uff1a\u6bd4\u5982-h\uff0c-l\uff0c-s\u7b49\u3002(- &nbsp; \u540e\u9762\u63a5\u5355\u4e2a\u5b57\u6bcd)<\/strong><\/p>\n<ul>\n<li>\n<p>\u77ed\u9009\u9879\u90fd\u662f\u4f7f\u7528\u2018-\u2019\u5f15\u5bfc\uff0c\u5f53\u6709\u591a\u4e2a\u77ed\u9009\u9879\u65f6\uff0c\u5404\u9009\u9879\u4e4b\u95f4\u4f7f\u7528\u7a7a\u683c\u9694\u5f00\u3002<\/p>\n<\/li>\n<li>\n<p>\u6709\u4e9b\u547d\u4ee4\u7684\u77ed\u9009\u9879\u53ef\u4ee5\u7ec4\u5408\uff0c\u6bd4\u5982-l \u2013h \u53ef\u4ee5\u7ec4\u5408\u4e3a\u2013lh<\/p>\n<\/li>\n<li>\n<p>\u6709\u4e9b\u547d\u4ee4\u7684\u77ed\u9009\u9879\u53ef\u4ee5\u4e0d\u5e26-\uff0c\u8fd9\u901a\u5e38\u53eb\u4f5cBSD\u98ce\u683c\u7684\u9009\u9879\uff0c\u6bd4\u5982ps aux<\/p>\n<\/li>\n<li>\n<p>\u6709\u4e9b\u77ed\u9009\u9879\u9700\u8981\u5e26\u9009\u9879\u672c\u8eab\u7684\u53c2\u6570\uff0c\u6bd4\u5982-L 512M<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u957f\u9009\u9879\uff1a\u6bd4\u5982&#8211;help\uff0c&#8211;list\u7b49\u3002(&#8211; &nbsp;\u540e\u9762\u63a5\u5355\u8bcd)<\/strong><\/p>\n<ul>\n<li>\n<p>\u957f\u9009\u9879\u90fd\u662f\u5b8c\u6574\u7684\u5355\u8bcd<\/p>\n<\/li>\n<li>\n<p>\u957f\u9009\u9879\u901a\u5e38\u4e0d\u80fd\u7ec4\u5408<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u9700\u8981\u53c2\u6570\uff0c\u957f\u9009\u9879\u7684\u53c2\u6570\u901a\u5e38\u9700\u8981\u2018=\u2019\uff0c\u6bd4\u5982&#8211;size=1G<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u53c2\u6570arguments<\/strong><strong>\uff1a<\/strong><\/p>\n<p>\u3000\u3000\u53c2\u6570\u662f\u6307\u547d\u4ee4\u7684\u4f5c\u7528\u5bf9\u8c61\u3002<\/p>\n<p>\u3000\u3000\u5982ls\u547d\u4ee4\uff0c\u4e0d\u52a0\u53c2\u6570\u7684\u65f6\u5019\u663e\u793a\u662f\u5f53\u524d\u76ee\u5f55\uff0c\u4e5f\u53ef\u4ee5\u52a0\u53c2\u6570\uff0c\u5982ls \/dev, \u5219\u8f93\u51fa\u7ed3\u679c\u662f\/dev\u76ee\u5f55\u3002<\/p>\n<p>\u3000\u3000\u4ee5\u4e0a\u7b80\u8981\u8bf4\u660e\u4e86\u9009\u9879\u53ca\u53c2\u6570\u7684\u533a\u522b\uff0c\u4f46\u5177\u4f53Linux\u4e2d\u54ea\u6761\u547d\u4ee4\u6709\u54ea\u4e9b\u9009\u9879\u53ca\u53c2\u6570\uff0c\u9700\u8981\u6211\u4eec\u9760\u7ecf\u9a8c\u79ef\u7d2f\u6216\u8005\u67e5\u770bLinux\u7684\u5e2e\u52a9\u4e86\u3002<\/p>\n<p><strong>\u603b\u7ed3:<\/strong><\/p>\n<p>\u9009\u9879\u662f\u9650\u5b9a\u7ed3\u679c\u7684\u663e\u793a\u7ed3\u679c\u3000\u3000<\/p>\n<ul>\n<li>\n<p>\u77ed\u9009\u9879(- &nbsp;\u4e00\u4e2a\u6a2a\u6760):\u53ea\u80fd\u4fee\u9970\u4e00\u4e2a\u5b57\u7b26\u7684\u9009\u9879\uff0c\u6bd4\u5982: ls -a,\u5f53\u7136\u591a\u4e2a\u77ed\u9009\u9879\u53ef\u4ee5\u5408\u5e76\uff0c\u6bd4\u5982tar -cvf<\/p>\n<\/li>\n<li>\n<p>\u957f\u9009\u9879(&#8211; &nbsp;\u4e24\u4e2a\u6a2a\u6760):\u53ef\u4ee5\u4fee\u9970\u5355\u4e2a\u5b57\u7b26\uff0c\u4e5f\u53ef\u4ee5\u4fee\u9970\u4e00\u4e2a\u5355\u8bcd\uff0c\u6bd4\u5982:<\/p>\n<p>(1) chkconfig &#8211;list<\/p>\n<p>(2)chkconfig &#8211;add xxx<\/p>\n<p>(3)service &#8211;status-all<\/p>\n<\/li>\n<\/ul>\n<p>\u53c2\u6570\u662f\u4f20\u9012\u5230\u811a\u672c\u4e2d\u7684\u771f\u5b9e\u7684\u53c2\u6570<\/p>\n<h3>\u547d\u4ee4\u884c\u9009\u9879\uff08option\uff09\u4e0e\u547d\u4ee4\u884c\u53c2\u6570\u7684\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<p>\u95ee\u9898\u63cf\u8ff0\uff1a\u5728linux shell\u4e2d\u5982\u4f55\u5904\u7406tail -n 10 access.log\u8fd9\u6837\u7684\u547d\u4ee4\u884c\u9009\u9879\uff1f<\/p>\n<p>\u5728bash\u4e2d\uff0c\u53ef\u4ee5\u7528\u4ee5\u4e0b\u4e09\u79cd\u65b9\u5f0f\u6765\u5904\u7406\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u6bcf\u79cd\u65b9\u5f0f\u90fd\u6709\u81ea\u5df1\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<ul>\n<li>\n<p>1\uff0c\u76f4\u63a5\u5904\u7406\uff0c\u4f9d\u6b21\u5bf9$1,$2,&#8230;,$n\u8fdb\u884c\u89e3\u6790\uff0c\u5206\u522b\u624b\u5de5\u5904\u7406\uff1b<\/p>\n<\/li>\n<li>\n<p>2\uff0cgetopts\u6765\u5904\u7406\uff0c\u5355\u4e2a\u5b57\u7b26\u9009\u9879\u7684\u60c5\u51b5\uff08\u5982\uff1a-n 10 -f file.txt\u7b49\u9009\u9879\uff09\uff1b<\/p>\n<\/li>\n<li>\n<p>3\uff0cgetopt\uff0c\u53ef\u4ee5\u5904\u7406\u5355\u4e2a\u5b57\u7b26\u9009\u9879\uff0c\u4e5f\u53ef\u4ee5\u5904\u7406\u957f\u9009\u9879long-option\uff08\u5982\uff1a&#8211;prefix=\/home\u7b49\uff09\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u603b\u7ed3\uff1a\u5c0f\u811a\u672c\u624b\u5de5\u5904\u7406\u5373\u53ef\uff0cgetopts\u80fd\u5904\u7406\u7edd\u5927\u591a\u6570\u7684\u60c5\u51b5\uff0cgetopt\u8f83\u590d\u6742\u3001\u529f\u80fd\u4e5f\u66f4\u5f3a\u5927\u3002<\/p>\n<p><strong>1\uff0c\u76f4\u63a5\u624b\u5de5\u5904\u7406\u4f4d\u7f6e\u53c2\u6570<\/strong><\/p>\n<p>\u5fc5\u987b\u8981\u8981\u77e5\u9053\u51e0\u4e2a\u53d8\u91cf<\/p>\n<pre>* &nbsp; &nbsp;$0 \uff1a\u5373\u547d\u4ee4\u672c\u8eab\uff0c\u76f8\u5f53\u4e8ec\/c++\u4e2d\u7684argv[0] &nbsp;\r\n* &nbsp; &nbsp;$1 \uff1a\u7b2c\u4e00\u4e2a\u53c2\u6570. &nbsp;\r\n* &nbsp; &nbsp;$2, $3, $4 ... \uff1a\u7b2c2\u30013\u30014\u4e2a\u53c2\u6570\uff0c\u4f9d\u6b21\u7c7b\u63a8\u3002 &nbsp;\r\n* &nbsp; &nbsp;$# &nbsp;\u53c2\u6570\u7684\u4e2a\u6570\uff0c\u4e0d\u5305\u62ec\u547d\u4ee4\u672c\u8eab &nbsp;\r\n* &nbsp; &nbsp;$@ \uff1a\u53c2\u6570\u672c\u8eab\u7684\u5217\u8868\uff0c\u4e5f\u4e0d\u5305\u62ec\u547d\u4ee4\u672c\u8eab &nbsp;\r\n* &nbsp; &nbsp;$* \uff1a\u548c$@\u76f8\u540c\uff0c\u4f46\"$*\" \u548c \"$@\"(\u52a0\u5f15\u53f7)\u5e76\u4e0d\u540c\uff0c\"$*\"\u5c06\u6240\u6709\u7684\u53c2\u6570\u89e3\u91ca\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u800c\"$@\"\r\n<\/pre>\n<p>\u662f\u4e00\u4e2a\u53c2\u6570\u6570\u7ec4\u3002<\/p>\n<p>\u624b\u5de5\u5904\u7406\u65b9\u5f0f\u80fd\u6ee1\u8db3\u591a\u6570\u7684\u7b80\u5355\u9700\u6c42\uff0c\u914d\u5408shift\u4f7f\u7528\u4e5f\u80fd\u6784\u9020\u51fa\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u4f46\u5904\u7406\u590d\u6742\u9009\u9879\u65f6\u5efa\u8bae\u7528\u4e0b\u9762\u7684\u4e24\u79cd\u65b9\u6cd5\u3002<\/p>\n<p>\u4f8b\u5b50\uff0c(getargs.sh)\uff1a<\/p>\n<pre>#!\/bin\/bash &nbsp;\r\nif [ $# -lt 1 ]; then &nbsp;\r\n &nbsp; &nbsp;echo \"error.. need args\" &nbsp;\r\n &nbsp; &nbsp;exit 1 &nbsp;fi &nbsp;\r\necho \"commond is $0\" &nbsp;echo \"args are:\" &nbsp;for arg in \"$@\" &nbsp;do &nbsp;\r\n &nbsp; &nbsp;echo $arg &nbsp;\r\ndone\r\n<\/pre>\n<p>\u8fd0\u884c\u547d\u4ee4\uff1a<\/p>\n<pre>.\/getargs.sh 11 22 cc &nbsp;\r\ncommond is .\/getargs.sh &nbsp;\r\nargs are: &nbsp;\r\n11 &nbsp;22 &nbsp;cc\r\n<\/pre>\n<p><strong>2\uff0cgetopts \uff08shell\u5185\u7f6e\u547d\u4ee4\uff09<\/strong><\/p>\n<p>\u5904\u7406\u547d\u4ee4\u884c\u53c2\u6570\u662f\u4e00\u4e2a\u76f8\u4f3c\u800c\u53c8\u590d\u6742\u7684\u4e8b\u60c5\uff0c\u4e3a\u6b64\uff0cc\u63d0\u4f9b\u4e86getopt\/getopt_long\u7b49\u51fd\u6570\uff0cc++\u7684boost\u63d0\u4f9b\u4e86<\/p>\n<p>options\u5e93\uff0c\u5728shell\u4e2d\uff0c\u5904\u7406\u6b64\u4e8b\u7684\u662fgetopts\u548cgetopt\u3002<\/p>\n<p>getopts\/getopt\u7684\u533a\u522b\uff0cgetopt\u662f\u4e2a\u5916\u90e8binary\u6587\u4ef6\uff0c\u800cgetopts\u662fshell builtin\u3002<\/p>\n<pre>[root@jbxue ~]$ type getopt &nbsp;\r\ngetopt is \/usr\/bin\/getopt &nbsp;\r\n[root@jbxue ~]$ type getopts &nbsp;\r\ngetopts is a shell builtin\r\n<\/pre>\n<p>getopts\u4e0d\u80fd\u76f4\u63a5\u5904\u7406\u957f\u7684\u9009\u9879\uff08\u5982\uff1a&#8211;prefix=\/home\u7b49\uff09<\/p>\n<p>\u5173\u4e8egetopts\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u53ef\u4ee5man bash &nbsp;\u641c\u7d22getopts<\/p>\n<p>getopts\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5305\u62ec\u5b57\u7b26\u548c\u201c\uff1a\u201d\uff0c\u6bcf\u4e00\u4e2a\u5b57\u7b26\u90fd\u662f\u4e00\u4e2a\u6709\u6548\u7684\u9009\u9879\uff0c\u5982\u679c<\/p>\n<p>\u5b57\u7b26\u540e\u9762\u5e26\u6709\u201c\uff1a\u201d\uff0c\u8868\u793a\u8fd9\u4e2a\u5b57\u7b26\u6709\u81ea\u5df1\u7684\u53c2\u6570\u3002getopts\u4ece\u547d\u4ee4\u4e2d\u83b7\u53d6\u8fd9\u4e9b\u53c2\u6570\uff0c\u5e76\u4e14\u5220\u53bb\u4e86\u201c-\u201d\uff0c\u5e76<\/p>\n<p>\u5c06\u5176\u8d4b\u503c\u5728\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e2d\uff0c\u5982\u679c\u5e26\u6709\u81ea\u5df1\u53c2\u6570\uff0c\u8fd9\u4e2a\u53c2\u6570\u8d4b\u503c\u5728\u201coptarg\u201d\u4e2d\u3002\u63d0\u4f9bgetopts\u7684shell\u5185\u7f6e\u4e86<\/p>\n<p>optarg\u8fd9\u4e2a\u53d8\u53d8\uff0cgetopts\u4fee\u6539\u4e86\u8fd9\u4e2a\u53d8\u91cf\u3002<\/p>\n<p>\u8fd9\u91cc\u53d8\u91cf$optarg\u5b58\u50a8\u76f8\u5e94\u9009\u9879\u7684\u53c2\u6570\uff0c\u800c$optind\u603b\u662f\u5b58\u50a8\u539f\u59cb$*\u4e2d\u4e0b\u4e00\u4e2a\u8981\u5904\u7406\u7684\u5143\u7d20\u4f4d\u7f6e\u3002<\/p>\n<p>while getopts &#8220;:a:bc&#8221; opt &nbsp;#\u7b2c\u4e00\u4e2a\u5192\u53f7\u8868\u793a\u5ffd\u7565\u9519\u8bef\uff1b\u5b57\u7b26\u540e\u9762\u7684\u5192\u53f7\u8868\u793a\u8be5\u9009\u9879\u5fc5\u987b\u6709\u81ea\u5df1\u7684\u53c2\u6570<\/p>\n<p>\u4f8b\u5b50\uff0c(getopts.sh)\uff1a<\/p>\n<pre>echo $* &nbsp;\r\nwhile getopts \":a:bc\" opt &nbsp;\r\ndo &nbsp;\r\n &nbsp; &nbsp; &nbsp; &nbsp;case $opt in &nbsp;\r\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a ) echo $optarg &nbsp;\r\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo $optind;; &nbsp;\r\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b ) echo \"b $optind\";; &nbsp;\r\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c ) echo \"c $optind\";; &nbsp;\r\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;? ) echo \"error\" &nbsp;\r\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit 1;; &nbsp;\r\n &nbsp; &nbsp; &nbsp; &nbsp;esac &nbsp;\r\ndone &nbsp;\r\necho $optind &nbsp;\r\nshift $(($optind - 1)) &nbsp;\r\n#\u901a\u8fc7shift $(($optind - 1))\u7684\u5904\u7406\uff0c$*\u4e2d\u5c31\u53ea\u4fdd\u7559\u4e86\u9664\u53bb\u9009\u9879\u5185\u5bb9\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u5728\u5176\u540e\u8fdb\u884c\u6b63\u5e38\u7684shell &nbsp;\r\n &nbsp;\r\n\u7f16\u7a0b\u5904\u7406\u4e86\u3002 &nbsp;\r\necho $0 &nbsp;echo $*\r\n<\/pre>\n<p>\u6267\u884c\u547d\u4ee4\uff1a<\/p>\n<pre>.\/getopts.sh -a 11 -b -c &nbsp;\r\n-a 11 -b -c &nbsp;\r\n11 &nbsp;3 &nbsp;b 4 &nbsp;c 5 &nbsp;5 &nbsp;.\/getopts.sh\r\n<\/pre>\n<p>3\uff0cgetopt\uff08\u4e00\u4e2a\u5916\u90e8\u5de5\u5177\uff09<\/p>\n<p>\u5177\u4f53\u7528\u7528\u6cd5\u53ef\u4ee5 man getopt<\/p>\n<ul>\n<li>\n<p>#-o\u8868\u793a\u77ed\u9009\u9879\uff0c\u4e24\u4e2a\u5192\u53f7\u8868\u793a\u8be5\u9009\u9879\u6709\u4e00\u4e2a\u53ef\u9009\u53c2\u6570\uff0c\u53ef\u9009\u53c2\u6570\u5fc5\u987b\u7d27\u8d34\u9009\u9879\uff0c\u5982-carg \u800c\u4e0d\u80fd\u662f-c arg<\/p>\n<\/li>\n<li>\n<p>#&#8211;long\u8868\u793a\u957f\u9009\u9879<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5b50\uff0c(getopt.sh)\uff1a<\/p>\n<pre>#!\/bin\/bash&nbsp;&nbsp;\n#&nbsp;a&nbsp;small&nbsp;example&nbsp;program&nbsp;for&nbsp;using&nbsp;the&nbsp;new&nbsp;getopt(1)&nbsp;program.&nbsp;&nbsp;\n#&nbsp;this&nbsp;program&nbsp;will&nbsp;only&nbsp;work&nbsp;with&nbsp;bash(1)&nbsp;&nbsp;\n#&nbsp;an&nbsp;similar&nbsp;program&nbsp;using&nbsp;the&nbsp;tcsh(1)&nbsp;script.&nbsp;language&nbsp;can&nbsp;be&nbsp;found&nbsp;&nbsp;\n#&nbsp;as&nbsp;parse.tcsh&nbsp;&nbsp;\n#&nbsp;example&nbsp;input&nbsp;and&nbsp;output&nbsp;(from&nbsp;the&nbsp;bash&nbsp;prompt):&nbsp;&nbsp;\n#&nbsp;.\/parse.bash&nbsp;-a&nbsp;par1&nbsp;'another&nbsp;arg'&nbsp;--c-long&nbsp;'wow!*\\?'&nbsp;-cmore&nbsp;-b&nbsp;\"&nbsp;very&nbsp;long&nbsp;\"&nbsp;&nbsp;#&nbsp;option&nbsp;a&nbsp;&nbsp;\n#&nbsp;option&nbsp;c,&nbsp;no&nbsp;argument&nbsp;&nbsp;\n#&nbsp;option&nbsp;c,&nbsp;argument&nbsp;`more'&nbsp;&nbsp;#&nbsp;option&nbsp;b,&nbsp;argument&nbsp;`&nbsp;very&nbsp;long&nbsp;'&nbsp;&nbsp;#&nbsp;remaining&nbsp;arguments:&nbsp;&nbsp;\n#&nbsp;--&gt;&nbsp;`par1'&nbsp;&nbsp;#&nbsp;--&gt;&nbsp;`another&nbsp;arg'&nbsp;&nbsp;#&nbsp;--&gt;&nbsp;`wow!*\\?'&nbsp;&nbsp;#&nbsp;note&nbsp;that&nbsp;we&nbsp;use&nbsp;`\"$@\"'&nbsp;to&nbsp;let&nbsp;each&nbsp;command-line&nbsp;parameter&nbsp;expand&nbsp;to&nbsp;a&nbsp;&nbsp;#&nbsp;separate&nbsp;word.&nbsp;the&nbsp;quotes&nbsp;around&nbsp;`$@'&nbsp;are&nbsp;essential!&nbsp;&nbsp;#&nbsp;we&nbsp;need&nbsp;temp&nbsp;as&nbsp;the&nbsp;`eval&nbsp;set&nbsp;--'&nbsp;would&nbsp;nuke&nbsp;the&nbsp;return&nbsp;value&nbsp;of&nbsp;getopt.&nbsp;&nbsp;#-o\u8868\u793a\u77ed\u9009\u9879\uff0c\u4e24\u4e2a\u5192\u53f7\u8868\u793a\u8be5\u9009\u9879\u6709\u4e00\u4e2a\u53ef\u9009\u53c2\u6570\uff0c\u53ef\u9009\u53c2\u6570\u5fc5\u987b\u7d27\u8d34\u9009\u9879&nbsp;&nbsp;\n#\u5982-carg&nbsp;\u800c\u4e0d\u80fd\u662f-c&nbsp;arg&nbsp;&nbsp;\n#--long\u8868\u793a\u957f\u9009\u9879&nbsp;&nbsp;\n#\"$@\"\u5728\u4e0a\u9762\u89e3\u91ca\u8fc7&nbsp;&nbsp;\n#&nbsp;-n:\u51fa\u9519\u65f6\u7684\u4fe1\u606f&nbsp;&nbsp;\n#&nbsp;--&nbsp;\uff1a\u4e3e\u4e00\u4e2a\u4f8b\u5b50\u6bd4\u8f83\u597d\u7406\u89e3\uff1a&nbsp;&nbsp;\n#\u6211\u4eec\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u5b57\u4e3a&nbsp;\"-f\"\u7684\u76ee\u5f55\u4f60\u4f1a\u600e\u4e48\u529e\uff1f&nbsp;&nbsp;\n#&nbsp;mkdir&nbsp;-f&nbsp;#\u4e0d\u6210\u529f\uff0c\u56e0\u4e3a-f\u4f1a\u88abmkdir\u5f53\u4f5c\u9009\u9879\u6765\u89e3\u6790\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u4f7f\u7528&nbsp;&nbsp;\n#&nbsp;mkdir&nbsp;--&nbsp;-f&nbsp;\u8fd9\u6837-f\u5c31\u4e0d\u4f1a\u88ab\u4f5c\u4e3a\u9009\u9879\u3002&nbsp;&nbsp;\ntemp=`getopt&nbsp;-o&nbsp;ab:c::&nbsp;--long&nbsp;a-long,b-long:,c-long::&nbsp;\\&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-n&nbsp;'example.bash'&nbsp;--&nbsp;\"$@\"`&nbsp;&nbsp;\nif&nbsp;[&nbsp;$?&nbsp;!=&nbsp;0&nbsp;]&nbsp;;&nbsp;then&nbsp;echo&nbsp;\"terminating...\"&nbsp;&gt;&amp;2&nbsp;;&nbsp;exit&nbsp;1&nbsp;;&nbsp;fi&nbsp;&nbsp;\n#&nbsp;note&nbsp;the&nbsp;quotes&nbsp;around&nbsp;`$temp':&nbsp;they&nbsp;are&nbsp;essential!&nbsp;&nbsp;#set&nbsp;\u4f1a\u91cd\u65b0\u6392\u5217\u53c2\u6570\u7684\u987a\u5e8f\uff0c\u4e5f\u5c31\u662f\u6539\u53d8$1,$2...$n\u7684\u503c\uff0c\u8fd9\u4e9b\u503c\u5728getopt\u4e2d\u91cd\u65b0\u6392\u5217\u8fc7\u4e86&nbsp;&nbsp;\neval&nbsp;set&nbsp;--&nbsp;\"$temp\"&nbsp;&nbsp;#\u7ecf\u8fc7getopt\u7684\u5904\u7406\uff0c\u4e0b\u9762\u5904\u7406\u5177\u4f53\u9009\u9879\u3002&nbsp;&nbsp;\nwhile&nbsp;true&nbsp;;&nbsp;do&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;\"$1\"&nbsp;in&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-a|--a-long)&nbsp;echo&nbsp;\"option&nbsp;a\"&nbsp;;&nbsp;shift&nbsp;;;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-b|--b-long)&nbsp;echo&nbsp;\"option&nbsp;b,&nbsp;argument&nbsp;\\`$2'\"&nbsp;;&nbsp;shift&nbsp;2&nbsp;;;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-c|--c-long)&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;c&nbsp;has&nbsp;an&nbsp;optional&nbsp;argument.&nbsp;as&nbsp;we&nbsp;are&nbsp;in&nbsp;quoted&nbsp;mode,&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;an&nbsp;empty&nbsp;parameter&nbsp;will&nbsp;be&nbsp;generated&nbsp;if&nbsp;its&nbsp;optional&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;argument&nbsp;is&nbsp;not&nbsp;found.&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;\"$2\"&nbsp;in&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"\")&nbsp;echo&nbsp;\"option&nbsp;c,&nbsp;no&nbsp;argument\";&nbsp;shift&nbsp;2&nbsp;;;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*)&nbsp;&nbsp;echo&nbsp;\"option&nbsp;c,&nbsp;argument&nbsp;\\`$2'\"&nbsp;;&nbsp;shift&nbsp;2&nbsp;;;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;esac&nbsp;;;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--)&nbsp;shift&nbsp;;&nbsp;break&nbsp;;;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*)&nbsp;echo&nbsp;\"internal&nbsp;error!\"&nbsp;;&nbsp;exit&nbsp;1&nbsp;;;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;esac&nbsp;&nbsp;\ndone&nbsp;&nbsp;\necho&nbsp;\"remaining&nbsp;arguments:\"&nbsp;&nbsp;for&nbsp;arg&nbsp;do&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;echo&nbsp;'--&gt;&nbsp;'\"\\`$arg'\"&nbsp;;&nbsp;&nbsp;\ndone<\/pre>\n<p>\u8fd0\u884c\u547d\u4ee4\uff1a<\/p>\n<pre>.\/getopt.sh&nbsp;--b-long&nbsp;abc&nbsp;-a&nbsp;-c33&nbsp;remain&nbsp;&nbsp;\noption&nbsp;b,&nbsp;argument&nbsp;`abc'&nbsp;&nbsp;\noption&nbsp;a&nbsp;&nbsp;\noption&nbsp;c,&nbsp;argument&nbsp;`33'&nbsp;&nbsp;\nremaining&nbsp;arguments:&nbsp;&nbsp;\n--&gt;&nbsp;`remain'<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300alinux\u6587\u6863\u4e2doption\u6307\u7684\u662f\u4ec0\u4e48\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>linux\u6587\u6863\u4e2doption\u6307\u7684\u662f\u4ec0\u4e48 \u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300alinux\u6587\u6863\u4e2doption\u6307\u7684\u662f\u4ec0\u4e48\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u7c73\u4e91\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002 \u5728linux\u4e2d\uff0coption\u662f\u6307\u547d\u4ee4\u9009\u9879\uff0c\u662f\u8c03\u6574\u547d\u4ee4\u6267\u884c\u884c\u4e3a\u7684\u5f00\u5173\uff0c\u5373\u9009\u9879\u4e0d\u540c\u51b3\u5b9a\u4e86\u547d\u4ee4\u7684\u663e\u793a\u7ed3\u679c\u4e0d\u540c\u3002option\uff08\u9009\u9879\uff09\u5206\u4e3a\u957f\u9009\u9879\u548c\u77ed\u9009\u9879\uff1a1\u3001\u77ed\u9009\u9879\u90fd\u662f\u4f7f\u7528\u201c-\u201d\u5f15\u5bfc\uff0c\u5f53\u6709\u591a\u4e2a\u77ed\u9009\u9879\u65f6\uff0c\u5404\u9009\u9879\u4e4b\u95f4\u4f7f\u7528\u7a7a\u683c\u9694\u5f00\uff1b2\u3001\u957f\u9009\u9879\u90fd\u662f\u5b8c\u6574\u7684\u5355\u8bcd\uff0c\u4e14\u901a\u5e38\u4e0d\u80fd\u7ec4\u5408\u3002 Linux\u4e2d\u547d\u4ee4\u9009\u9879\uff08option\uff09\u53ca\u53c2\u6570\u7b80\u4ecb \u767b\u5f55Linux\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728#\u6216$\u7b26\u540e\u9762\u53bb\u8f93\u5165\u547d\u4ee4\uff0c\u6709\u7684\u65f6\u5019\u547d\u4ee4\u540e\u9762\u8fd8\u4f1a\u8ddf\u7740\u201c\u9009\u9879\u201d\uff08\u82f1\u6587options\uff09\u6216\u201c\u53c2\u6570\u201d\uff08\u82f1\u6587arguments\uff09\u3002\u5373Linux\u4e2d\u547d\u4ee4\u683c\u5f0f\u4e3a\uff1a command [options] [arguments] \/\/\u4e2d\u62ec\u53f7\u4ee3\u8868\u662f\u53ef\u9009\u7684\uff0c\u5373\u6709\u4e9b\u547d\u4ee4\u4e0d\u9700\u8981\u9009\u9879\u4e5f\u4e0d\u9700\u8981\u53c2\u6570\uff0c\u4f46\u6709\u7684\u547d\u4ee4\u5728\u8fd0\u884c\u65f6\u9700\u8981\u591a\u4e2a\u9009\u9879\u6216\u53c2\u6570\u3002 \u9009\u9879options\uff1a \u9009\u9879\u662f\u8c03\u6574\u547d\u4ee4\u6267\u884c\u884c\u4e3a\u7684\u5f00\u5173\uff0c\u5373\uff0c\u9009\u9879\u4e0d\u540c\u51b3\u5b9a\u4e86\u547d\u4ee4\u7684\u663e\u793a\u7ed3\u679c\u4e0d\u540c\u3002 \u9009\u9879\u5206\u4e3a\u957f\u9009\u9879\u548c\u77ed\u9009\u9879\u3002 \u77ed\u9009\u9879\uff1a\u6bd4\u5982-h\uff0c-l\uff0c-s\u7b49\u3002(- &nbsp; \u540e\u9762\u63a5\u5355\u4e2a\u5b57\u6bcd) \u77ed\u9009\u9879\u90fd\u662f\u4f7f\u7528\u2018-\u2019\u5f15\u5bfc\uff0c\u5f53\u6709\u591a\u4e2a\u77ed\u9009\u9879\u65f6\uff0c\u5404\u9009\u9879\u4e4b\u95f4\u4f7f\u7528\u7a7a\u683c\u9694\u5f00\u3002 \u6709\u4e9b\u547d\u4ee4\u7684\u77ed\u9009\u9879\u53ef\u4ee5\u7ec4\u5408\uff0c\u6bd4\u5982-l \u2013h \u53ef\u4ee5\u7ec4\u5408\u4e3a\u2013lh \u6709\u4e9b\u547d\u4ee4\u7684\u77ed\u9009\u9879\u53ef\u4ee5\u4e0d\u5e26-\uff0c\u8fd9\u901a\u5e38\u53eb\u4f5cBSD\u98ce\u683c\u7684\u9009\u9879\uff0c\u6bd4\u5982ps aux \u6709\u4e9b\u77ed\u9009\u9879\u9700\u8981\u5e26\u9009\u9879\u672c\u8eab\u7684\u53c2\u6570\uff0c\u6bd4\u5982-L 512M \u957f\u9009\u9879\uff1a\u6bd4\u5982&#8211;help\uff0c&#8211;list\u7b49\u3002(&#8211; &nbsp;\u540e\u9762\u63a5\u5355\u8bcd) \u957f\u9009\u9879\u90fd\u662f\u5b8c\u6574\u7684\u5355\u8bcd \u957f\u9009\u9879\u901a\u5e38\u4e0d\u80fd\u7ec4\u5408 \u5982\u679c\u9700\u8981\u53c2\u6570\uff0c\u957f\u9009\u9879\u7684\u53c2\u6570\u901a\u5e38\u9700\u8981\u2018=\u2019\uff0c\u6bd4\u5982&#8211;size=1G \u53c2\u6570arguments\uff1a \u3000\u3000\u53c2\u6570\u662f\u6307\u547d\u4ee4\u7684\u4f5c\u7528\u5bf9\u8c61\u3002 \u3000\u3000\u5982ls\u547d\u4ee4\uff0c\u4e0d\u52a0\u53c2\u6570\u7684\u65f6\u5019\u663e\u793a\u662f\u5f53\u524d\u76ee\u5f55\uff0c\u4e5f\u53ef\u4ee5\u52a0\u53c2\u6570\uff0c\u5982ls \/dev, \u5219\u8f93\u51fa\u7ed3\u679c\u662f\/dev\u76ee\u5f55\u3002 \u3000\u3000\u4ee5\u4e0a\u7b80\u8981\u8bf4\u660e\u4e86\u9009\u9879\u53ca\u53c2\u6570\u7684\u533a\u522b\uff0c\u4f46\u5177\u4f53Linux\u4e2d\u54ea\u6761\u547d\u4ee4\u6709\u54ea\u4e9b\u9009\u9879\u53ca\u53c2\u6570\uff0c\u9700\u8981\u6211\u4eec\u9760\u7ecf\u9a8c\u79ef\u7d2f\u6216\u8005\u67e5\u770bLinux\u7684\u5e2e\u52a9\u4e86\u3002 \u603b\u7ed3: \u9009\u9879\u662f\u9650\u5b9a\u7ed3\u679c\u7684\u663e\u793a\u7ed3\u679c\u3000\u3000 \u77ed\u9009\u9879(- &nbsp;\u4e00\u4e2a\u6a2a\u6760):\u53ea\u80fd\u4fee\u9970\u4e00\u4e2a\u5b57\u7b26\u7684\u9009\u9879\uff0c\u6bd4\u5982: ls -a,\u5f53\u7136\u591a\u4e2a\u77ed\u9009\u9879\u53ef\u4ee5\u5408\u5e76\uff0c\u6bd4\u5982tar -cvf \u957f\u9009\u9879(&#8211; &nbsp;\u4e24\u4e2a\u6a2a\u6760):\u53ef\u4ee5\u4fee\u9970\u5355\u4e2a\u5b57\u7b26\uff0c\u4e5f\u53ef\u4ee5\u4fee\u9970\u4e00\u4e2a\u5355\u8bcd\uff0c\u6bd4\u5982: (1) chkconfig &#8211;list (2)chkconfig &#8211;add xxx (3)service &#8211;status-all \u53c2\u6570\u662f\u4f20\u9012\u5230\u811a\u672c\u4e2d\u7684\u771f\u5b9e\u7684\u53c2\u6570 \u547d\u4ee4\u884c\u9009\u9879\uff08option\uff09\u4e0e\u547d\u4ee4\u884c\u53c2\u6570\u7684\u4f7f\u7528\u65b9\u6cd5 \u95ee\u9898\u63cf\u8ff0\uff1a\u5728linux shell\u4e2d\u5982\u4f55\u5904\u7406tail [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-52258","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52258"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52258\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}