{"id":283,"date":"2025-06-17T16:33:27","date_gmt":"2025-06-17T08:33:27","guid":{"rendered":"https:\/\/qkd.koudaipc.com\/?p=283"},"modified":"2025-06-17T16:33:27","modified_gmt":"2025-06-17T08:33:27","slug":"posix-shell-%e7%bc%96%e7%a8%8b%e4%b9%a6%e7%b1%8d%e6%8e%a8%e8%8d%90","status":"publish","type":"post","link":"https:\/\/qkd.koudaipc.com\/en\/2025\/06\/17\/posix-shell-%e7%bc%96%e7%a8%8b%e4%b9%a6%e7%b1%8d%e6%8e%a8%e8%8d%90\/","title":{"rendered":"POSIX Shell \u7f16\u7a0b\u4e66\u7c4d\u63a8\u8350"},"content":{"rendered":"<p>\ufe0f \u5bfb\u627e\u4f18\u79c0\u7684 POSIX Shell \u7f16\u7a0b\u4e66\u7c4d\u662f\u4e2a\u660e\u667a\u7684\u9009\u62e9\uff01\u4e13\u6ce8\u4e8e POSIX \u6807\u51c6\u610f\u5473\u7740\u4f60\u7f16\u5199\u7684\u811a\u672c\u5c06\u5177\u6709\u66f4\u597d\u7684<strong>\u53ef\u79fb\u690d\u6027<\/strong>\uff0c\u80fd\u5728\u66f4\u5e7f\u6cdb\u7684 Unix\/Linux \u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u6211\u7cbe\u5fc3\u6311\u9009\u7684\u51e0\u672c\u7ecf\u5178\u4e14\u503c\u5f97\u63a8\u8350\u7684\u4e66\u7c4d\uff0c\u5b83\u4eec\u90fd\u5f3a\u8c03\u6216\u7b26\u5408 POSIX \u6807\u51c6\uff1a<\/p>\n<p>\ud83d\udcda <strong>1. \u300aClassic Shell Scripting\u300b<\/strong><\/p>\n<ul>\n<li><strong>\u4f5c\u8005:<\/strong> Arnold Robbins, Nelson H.F. Beebe<\/li>\n<li><strong>\u63a8\u8350\u7406\u7531:<\/strong> \u8fd9\u672c\u4e66\u582a\u79f0 POSIX Shell \u811a\u672c\u7f16\u7a0b\u7684<strong>\u9ec4\u91d1\u6807\u51c6<\/strong>\u3002\u5b83\u4e0d\u5c40\u9650\u4e8e\u4efb\u4f55\u7279\u5b9a\u7684 Shell\uff08\u5982 Bash\uff09\uff0c\u800c\u662f\u4e13\u6ce8\u4e8e POSIX Shell \u7684\u6838\u5fc3\u529f\u80fd\u548c\u7f16\u5199\u5065\u58ee\u3001\u53ef\u79fb\u690d\u811a\u672c\u7684\u6700\u4f73\u5b9e\u8df5\u3002\u5185\u5bb9\u4ece\u57fa\u7840\u8bed\u6cd5\u8bb2\u8d77\uff0c\u6df1\u5165\u8bb2\u89e3\u6587\u672c\u5904\u7406\uff08grep, sed, awk\uff09\u3001\u6d41\u7a0b\u63a7\u5236\u3001\u51fd\u6570\u3001\u4fe1\u53f7\u5904\u7406\u3001\u811a\u672c\u8c03\u8bd5\u7b49\u6838\u5fc3\u4e3b\u9898\uff0c\u5e76\u5305\u542b\u5927\u91cf\u5b9e\u7528\u7684\u771f\u5b9e\u4e16\u754c\u811a\u672c\u6848\u4f8b\uff08\u5982\u65e5\u5fd7\u8f6e\u8f6c\u3001\u7cfb\u7edf\u62a5\u544a\uff09\u3002\u7279\u522b\u5f3a\u8c03\u53ef\u79fb\u690d\u6027\u548c\u907f\u514d\u975e\u6807\u51c6\u6269\u5c55\u3002\u662f<strong>\u7cfb\u7edf\u7ba1\u7406\u5458\u548c\u5f00\u53d1\u8005\u6df1\u5165\u5b66\u4e60 Shell \u7684\u7edd\u4f73\u9009\u62e9<\/strong>\u3002<\/li>\n<\/ul>\n<p>\ud83d\udcda <strong>2. \u300aThe Unix Programming Environment\u300b<\/strong><\/p>\n<ul>\n<li><strong>\u4f5c\u8005:<\/strong> Brian W. Kernighan, Rob Pike<\/li>\n<li><strong>\u63a8\u8350\u7406\u7531:<\/strong> \u8fd9\u662f\u4e00\u672c<strong>\u6c38\u6052\u7684\u7ecf\u5178<\/strong>\uff01\u867d\u7136\u51fa\u7248\u8f83\u65e9\u4e14\u5185\u5bb9\u4e0d\u5c40\u9650\u4e8e Shell\uff08\u6db5\u76d6\u4e86 Unix \u54f2\u5b66\u3001\u6587\u4ef6\u7cfb\u7edf\u3001\u8fc7\u6ee4\u5668\u3001\u7f16\u7a0b\u5de5\u5177\u5982 yacc\/lex\uff09\uff0c\u4f46\u5176\u5173\u4e8e Shell \u7f16\u7a0b\u7684\u90e8\u5206\uff08\u4f7f\u7528\u7ecf\u5178\u7684 Bourne Shell\uff09\u975e\u5e38\u7cbe\u70bc\u548c\u6df1\u523b\u3002Kernighan \u662f Unix \u548c C \u8bed\u8a00\u53d1\u5c55\u7684\u5173\u952e\u4eba\u7269\uff0c\u672c\u4e66\u6e05\u6670\u9610\u8ff0\u4e86 Unix \u5de5\u5177\u94fe\uff08\u5305\u62ec Shell\uff09\u5982\u4f55\u534f\u540c\u5de5\u4f5c\u6765\u89e3\u51b3\u590d\u6742\u95ee\u9898\u3002\u5b66\u4e60\u5176\u4e2d\u7684 Shell \u90e8\u5206\u80fd\u6253\u4e0b<strong>\u6781\u5176\u575a\u5b9e\u7684\u601d\u60f3\u548c\u98ce\u683c\u57fa\u7840<\/strong>\uff0c\u7406\u89e3 Shell \u5728 Unix \u73af\u5883\u4e2d\u7684\u6838\u5fc3\u5730\u4f4d\u3002\u5c3d\u7ba1\u6709\u4e9b\u5de5\u5177\u7ec6\u8282\u53ef\u80fd\u66f4\u65b0\uff0c\u4f46\u5176\u54f2\u5b66\u548c\u6838\u5fc3\u6982\u5ff5\u6c38\u4e0d\u8fc7\u65f6\u3002<\/li>\n<\/ul>\n<p>\ud83d\udcda <strong>3. \u300aLearning the bash Shell\u300b<\/strong><\/p>\n<ul>\n<li><strong>\u4f5c\u8005:<\/strong> Cameron Newham, Bill Rosenblatt<\/li>\n<li><strong>\u63a8\u8350\u7406\u7531:<\/strong> \u8fd9\u672c\u4e66\u662f O'Reilly &quot;\u52a8\u7269\u4e66&quot;\u7cfb\u5217\u4e2d\u7684\u7ecf\u5178\u3002\u867d\u7136\u4e66\u540d\u662f &quot;bash&quot;\uff0c\u4f46<strong>\u7b2c\u4e09\u7248\u53ca\u4ee5\u540e\u7684\u7248\u672c\u5bf9 POSIX \u517c\u5bb9\u6027\u7ed9\u4e88\u4e86\u76f8\u5f53\u5927\u7684\u5173\u6ce8<\/strong>\u3002\u5b83\u6e05\u6670\u5730\u6807\u660e\u4e86\u54ea\u4e9b\u7279\u6027\u662f POSIX \u6807\u51c6\u7684\uff0c\u54ea\u4e9b\u662f Bash \u7684\u6269\u5c55\u3002\u5185\u5bb9\u5168\u9762\uff0c\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u4e3b\u9898\uff08\u5982\u547d\u4ee4\u884c\u7f16\u8f91\u3001\u4f5c\u4e1a\u63a7\u5236\u3001\u7f16\u7a0b\u6280\u5de7\uff09\u90fd\u6709\u6db5\u76d6\uff0c\u5e76\u5305\u542b\u8bb8\u591a\u5b9e\u7528\u811a\u672c\u793a\u4f8b\u3002\u5982\u679c\u4f60\u60f3\u5728<strong>\u786e\u4fdd POSIX \u57fa\u7840\u7684\u540c\u65f6\uff0c\u4e5f\u80fd\u5145\u5206\u5229\u7528\u5f53\u524d Linux\/macOS \u7b49\u4e3b\u6d41\u73af\u5883\u4e2d\u6700\u5e38\u89c1\u7684 Bash \u63d0\u4f9b\u7684\u4fbf\u5229\u6269\u5c55<\/strong>\uff0c\u8fd9\u672c\u4e66\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u5e73\u8861\u9009\u62e9\u3002\u8bf7\u6ce8\u610f\u9009\u62e9\u8f83\u65b0\u7684\u7248\u672c\uff08\u7b2c\u4e09\u7248\u6216\u66f4\u9ad8\uff09\u3002<\/li>\n<\/ul>\n<p>\ud83d\udcda <strong>4. \u300aUnix Shell Programming\u300b<\/strong><\/p>\n<ul>\n<li><strong>\u4f5c\u8005:<\/strong> Stephen G. Kochan, Patrick H. Wood<\/li>\n<li><strong>\u63a8\u8350\u7406\u7531:<\/strong> \u8fd9\u4e5f\u662f\u4e00\u672c\u5907\u53d7\u63a8\u5d07\u7684\u7ecf\u5178\u6559\u6750\uff0c\u4e13\u6ce8\u4e8e<strong>\u6807\u51c6 Bourne Shell<\/strong>\uff08\u5373 POSIX Shell \u7684\u57fa\u7840\uff09\u3002\u5185\u5bb9\u7ec4\u7ec7\u6e05\u6670\uff0c\u5faa\u5e8f\u6e10\u8fdb\uff0c\u8bb2\u89e3\u7ec6\u81f4\uff0c\u975e\u5e38\u9002\u5408\u4f5c\u4e3a\u6559\u6750\u81ea\u5b66\u3002\u5b83\u7cfb\u7edf\u5730\u8986\u76d6\u4e86 Shell \u7f16\u7a0b\u7684\u6240\u6709\u6838\u5fc3\u6982\u5ff5\uff1a\u53d8\u91cf\u3001\u53c2\u6570\u3001\u6d41\u7a0b\u63a7\u5236\u3001I\/O\u3001\u51fd\u6570\u3001\u8c03\u8bd5\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u7b49\uff0c\u5e76\u5f3a\u8c03\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u3002\u662f\u6253\u7262 POSIX Shell \u57fa\u7840\u7684\u597d\u4e66\u3002<\/li>\n<\/ul>\n<p>\ud83d\udcd8 <strong>\u8865\u5145\u5efa\u8bae\u548c\u8d44\u6e90\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u300aPOSIX \u89c4\u8303\u672c\u8eab\u300b:<\/strong>\n<ul>\n<li><strong>\u5728\u7ebf\u8d44\u6e90:<\/strong> \u6700\u6743\u5a01\u7684\u53c2\u8003\u5f53\u7136\u662f <a href=\"https:\/\/pubs.opengroup.org\/onlinepubs\/9699919799\/\">The Open Group Base Specifications<\/a>\u3002\u641c\u7d22 &quot;Shell Command Language&quot; \u7ae0\u8282\u3002\u867d\u7136\u8bfb\u8d77\u6765\u50cf\u6280\u672f\u6587\u6863\uff0c\u4f46\u5bf9\u4e8e\u7406\u89e3\u6807\u51c6\u7ec6\u8282\u548c\u8fb9\u754c\u60c5\u51b5\u81f3\u5173\u91cd\u8981\u3002<\/li>\n<li><strong><code>man<\/code> \u624b\u518c:<\/strong> \u5728\u7ec8\u7aef\u4e2d\u8f93\u5165 <code>man sh<\/code> \u6216 <code>man bash<\/code>\uff08\u5e76\u4ed4\u7ec6\u67e5\u770b\u5176\u4e2d\u6807\u660e &quot;POSIX&quot; \u6216 &quot;Portable&quot; \u7684\u90e8\u5206\uff09\u662f\u65e5\u5e38\u5feb\u901f\u67e5\u8be2\u7684\u6700\u4f73\u65b9\u5f0f\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5728\u7ebf\u5de5\u5177:<\/strong>\n<ul>\n<li><strong><a href=\"https:\/\/www.shellcheck.net\/\">ShellCheck<\/a><\/strong>: \u4e00\u4e2a<strong>\u6781\u5176\u6709\u7528<\/strong>\u7684\u9759\u6001\u5206\u6790\u5de5\u5177\uff0c\u80fd\u68c0\u67e5 Shell \u811a\u672c\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\u3001\u5e38\u89c1\u9677\u9631\u3001\u53ef\u79fb\u690d\u6027\u95ee\u9898\uff08\u5b83\u4f1a\u660e\u786e\u6307\u51fa\u54ea\u4e9b\u7528\u6cd5\u4e0d\u7b26\u5408 POSIX\uff09\u3002\u5f3a\u70c8\u5efa\u8bae\u5728\u7f16\u5199\u811a\u672c\u65f6\u4f7f\u7528\uff01<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5b9e\u8df5:<\/strong>\n<ul>\n<li>\u6700\u597d\u7684\u5b66\u4e60\u65b9\u6cd5\u662f<strong>\u8fb9\u5b66\u8fb9\u7ec3<\/strong>\u3002\u5c1d\u8bd5\u7528\u5b66\u5230\u7684\u77e5\u8bc6\u81ea\u52a8\u5316\u65e5\u5e38\u4efb\u52a1\uff0c\u5373\u4f7f\u662f\u7b80\u5355\u7684\u4efb\u52a1\u3002<\/li>\n<li>\u4f7f\u7528 <code>\/bin\/sh<\/code>\uff08\u901a\u5e38\u662f\u6307\u5411\u7cfb\u7edf\u9ed8\u8ba4 POSIX Shell \u7684\u94fe\u63a5\uff0c\u5982 <code>dash<\/code> \u6216 <code>bash<\/code> \u7684 POSIX \u6a21\u5f0f\uff09\u6765\u8fd0\u884c\u4f60\u7684\u811a\u672c\uff0c\u4ee5\u6d4b\u8bd5\u5176\u53ef\u79fb\u690d\u6027\u3002\u53ef\u4ee5\u901a\u8fc7 <code>#!\/bin\/sh<\/code> \u6307\u5b9a\u89e3\u91ca\u5668\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u6ce8\u610f\u4e66\u7c4d\u7248\u672c:<\/strong> \u4f18\u5148\u9009\u62e9\u4f60\u80fd\u627e\u5230\u7684<strong>\u6700\u65b0\u7248\u672c<\/strong>\uff0c\u56e0\u4e3a Shell \u6807\u51c6\u548c\u5b9e\u8df5\u4e5f\u5728\u7f13\u6162\u6f14\u8fdb\u3002<\/li>\n<\/ul>\n<p>\ud83d\udccc <strong>\u603b\u7ed3:<\/strong><\/p>\n<ul>\n<li><strong>\u8ffd\u6c42\u7eaf\u7cb9\u7684 POSIX \u6807\u51c6\u3001\u6700\u4f73\u5b9e\u8df5\u548c\u6df1\u5ea6:<\/strong> \u9996\u9009 <strong>\u300aClassic Shell Scripting\u300b<\/strong>\u3002<\/li>\n<li><strong>\u60f3\u7406\u89e3 Unix \u54f2\u5b66\u548c Shell \u5728\u5176\u4e2d\u7684\u89d2\u8272\uff0c\u6253\u4e0b\u575a\u5b9e\u57fa\u7840:<\/strong> \u5fc5\u8bfb <strong>\u300aThe Unix Programming Environment\u300b<\/strong>\u3002<\/li>\n<li><strong>\u9700\u8981\u4e00\u4e2a\u5e73\u8861\u70b9\uff08POSIX + \u4e3b\u6d41 Bash \u6269\u5c55\u7684\u5b9e\u7528\u6307\u5357\uff09:<\/strong> <strong>\u300aLearning the bash Shell\u300b<\/strong> (\u8f83\u65b0\u7248) \u662f\u7406\u60f3\u9009\u62e9\u3002<\/li>\n<li><strong>\u5bfb\u627e\u4e00\u672c\u6e05\u6670\u3001\u7cfb\u7edf\u7684\u6807\u51c6 Shell \u6559\u6750:<\/strong> <strong>\u300aUnix Shell Programming\u300b<\/strong> \u503c\u5f97\u4fe1\u8d56\u3002<\/li>\n<\/ul>\n<p>\u65e0\u8bba\u4f60\u9009\u62e9\u54ea\u4e00\u672c\uff0c\u914d\u5408 <strong>ShellCheck<\/strong> \u5de5\u5177\u548c\u67e5\u9605\u5728\u7ebf <strong><code>man<\/code> \u624b\u518c\/POSIX \u89c4\u8303<\/strong>\uff0c\u4f60\u5c06\u80fd\u7f16\u5199\u51fa\u5065\u58ee\u3001\u53ef\u79fb\u690d\u4e14\u9ad8\u6548\u7684 POSIX Shell \u811a\u672c\u3002\u795d\u4f60\u5728Shell\u7f16\u7a0b\u4e4b\u65c5\u4e2d\u987a\u5229\uff01\ud83d\udcbb\ud83d\ude80<\/p>","protected":false},"excerpt":{"rendered":"<p>\ufe0f \u5bfb\u627e\u4f18\u79c0\u7684 POSIX Shell \u7f16\u7a0b\u4e66\u7c4d\u662f\u4e2a\u660e\u667a\u7684\u9009\u62e9\uff01\u4e13\u6ce8\u4e8e POSIX \u6807\u51c6\u610f\u5473\u7740\u4f60\u7f16\u5199\u7684\u811a\u672c\u5c06\u5177 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pmpro_default_level":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-uncategorized","pmpro-has-access"],"_links":{"self":[{"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":1,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":284,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/posts\/283\/revisions\/284"}],"wp:attachment":[{"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}