{"id":2337,"date":"2017-11-18T10:58:48","date_gmt":"2017-11-18T02:58:48","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2337"},"modified":"2017-11-18T10:58:48","modified_gmt":"2017-11-18T02:58:48","slug":"shell-bash-%e8%84%9a%e6%9c%ac-%e7%ae%80%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2337","title":{"rendered":"Shell bash \u811a\u672c \u7b80\u4ecb"},"content":{"rendered":"<p>\n\t\u670d\u52a1\u5668\u7684\u5f00\u53d1\u548c\u7ba1\u7406\u79bb\u4e0d\u5f00 Bash \u811a\u672c\uff0c\u638c\u63e1\u5b83\u9700\u8981\u5b66\u4e60\u5927\u91cf\u7684\u7ec6\u8282\u3002BASH \u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u811a\u672c\u8bed\u8a00,\u4e0d\u8fc7\u4e3a\u4e86\u65b9\u4fbf\u7ed3\u6784\u5316\u7684\u8bbe\u8ba1\uff0cBASH \u4e2d\u4e5f\u63d0\u4f9b\u4e86\u51fd\u6570\u5b9a\u4e49\u7684\u529f\u80fd\u3002set\u547d\u4ee4\u662f Bash \u811a\u672c\u7684\u91cd\u8981\u73af\u8282\uff0c\u5374\u5e38\u5e38\u88ab\u5ffd\u89c6\uff0c\u5bfc\u81f4\u811a\u672c\u7684\u5b89\u5168\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u51fa\u95ee\u9898\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd BASH \u7684\u7b80\u4ecb\u548c\u5386\u53f2\u3002\n<\/p>\n<p>\n\tbash \u662f\u4e00\u4e2a\u4e3aGNU\u8ba1\u5212\u7f16\u5199\u7684Unix shell\u3002\u5b83\u7684\u540d\u5b57\u662f\u4e00\u7cfb\u5217\u7f29\u5199\uff1aBourne-Again SHell &mdash; \u8fd9\u662f\u5173\u4e8eBourne shell\uff08sh\uff09\u7684\u4e00\u4e2a\u53cc\u5173\u8bed\uff08Bourne again \/ born again\uff09\u3002Bourne shell\u662f\u4e00\u4e2a\u65e9\u671f\u7684\u91cd\u8981shell\uff0c\u7531\u53f2\u8482\u592b&middot;\u4f2f\u6069\u57281978\u5e74\u524d\u540e\u7f16\u5199\uff0c\u5e76\u540cVersion 7 Unix\u4e00\u8d77\u53d1\u5e03\u3002bash\u5219\u57281987\u5e74\u7531\u5e03\u83b1\u6069&middot;\u798f\u514b\u65af\u521b\u9020\u3002\u57281990\u5e74\uff0cChet Ramey\u6210\u4e3a\u4e86\u4e3b\u8981\u7684\u7ef4\u62a4\u8005\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Bash \u811a\u672c\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2017\/bg2017111501.png\" style=\"width: 376px;height: 158px\" \/>\n<\/p>\n<p>\n\tbash\u662f\u5927\u591a\u6570Linux\u7cfb\u7edf\u4ee5\u53caMac OS X\u9ed8\u8ba4\u7684shell\uff0c\u5b83\u80fd\u8fd0\u884c\u4e8e\u5927\u591a\u6570\u7c7bUnix\u98ce\u683c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u4e0a\uff0c\u751a\u81f3\u88ab\u79fb\u690d\u5230\u4e86Microsoft Windows\u4e0a\u7684Cygwin\u7cfb\u7edf\u4e2d\uff0c\u4ee5\u5b9e\u73b0Windows\u7684POSIX\u865a\u62df\u63a5\u53e3\u3002\u6b64\u5916\uff0c\u5b83\u4e5f\u88abDJGPP\u9879\u76ee\u79fb\u690d\u5230\u4e86MS-DOS\u4e0a\u3002\n<\/p>\n<p>\n\tbash\u7684\u547d\u4ee4\u8bed\u6cd5\u662fBourne shell\u547d\u4ee4\u8bed\u6cd5\u7684\u8d85\u96c6\u3002\u6570\u91cf\u5e9e\u5927\u7684Bourne shell\u811a\u672c\u5927\u591a\u4e0d\u7ecf\u4fee\u6539\u5373\u53ef\u4ee5\u5728bash\u4e2d\u6267\u884c\uff0c\u53ea\u6709\u4f7f\u7528\u4e86Bourne\u7684\u7279\u6b8a\u53d8\u91cf\u6216\u5185\u7f6e\u547d\u4ee4\u7684\u811a\u672c\u624d\u9700\u8981\u4fee\u6539\u3002 bash\u7684\u547d\u4ee4\u8bed\u6cd5\u5f88\u591a\u6765\u81eaKorn shell (ksh) \u548c C shell (csh)\uff0c \u4f8b\u5982\u547d\u4ee4\u884c\u7f16\u8f91\uff0c\u547d\u4ee4\u5386\u53f2\uff0c\u76ee\u5f55\u6808\uff0c$RANDOM \u548c $PPID \u53d8\u91cf\uff0c\u4ee5\u53caPOSIX\u7684\u547d\u4ee4\u7f6e\u6362\u8bed\u6cd5\uff1a $(&#8230;)\u3002\u4f5c\u4e3a\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7684shell\uff0c\u6309\u4e0bTAB\u952e\u5373\u53ef\u81ea\u52a8\u8865\u5168\u5df2\u90e8\u5206\u8f93\u5165\u7684\u7a0b\u5e8f\u540d\u3001\u6587\u4ef6\u540d\u3001\u53d8\u91cf\u540d\u7b49\u7b49\u3002\n<\/p>\n<p>\n\t\u6211\u4eec\u77e5\u9053\uff0cBash \u6267\u884c\u811a\u672c\u7684\u65f6\u5019\uff0c\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Shell\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\n$ bash script.sh<\/pre>\n<p>\n\t\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c<code>script.sh<\/code>\u662f\u5728\u4e00\u4e2a\u65b0\u7684 Shell \u91cc\u9762\u6267\u884c\u3002\u8fd9\u4e2a Shell \u5c31\u662f\u811a\u672c\u7684\u6267\u884c\u73af\u5883\uff0cBash \u9ed8\u8ba4\u7ed9\u5b9a\u4e86\u8fd9\u4e2a\u73af\u5883\u7684\u5404\u79cd\u53c2\u6570\u3002\n<\/p>\n<p>\n\t<code>set<\/code>\u547d\u4ee4\u7528\u6765\u4fee\u6539 Shell \u73af\u5883\u7684\u8fd0\u884c\u53c2\u6570\uff0c\u4e5f\u5c31\u662f\u53ef\u4ee5\u5b9a\u5236\u73af\u5883\u3002\u4e00\u5171\u6709\u5341\u51e0\u4e2a\u53c2\u6570\u53ef\u4ee5\u5b9a\u5236\uff0c<a href=\"https:\/\/www.gnu.org\/software\/bash\/manual\/html_node\/The-Set-Builtin.html\" target=\"_blank\">\u5b98\u65b9\u624b\u518c<\/a>\u6709\u5b8c\u6574\u6e05\u5355\uff0c\u672c\u6587\u4ecb\u7ecd\u5176\u4e2d\u6700\u5e38\u7528\u7684\u56db\u4e2a\u3002\n<\/p>\n<p>\n\t\u987a\u4fbf\u63d0\u4e00\u4e0b\uff0c\u5982\u679c\u547d\u4ee4\u884c\u4e0b\u4e0d\u5e26\u4efb\u4f55\u53c2\u6570\uff0c\u76f4\u63a5\u8fd0\u884c<code>set<\/code>\uff0c\u4f1a\u663e\u793a\u6240\u6709\u7684\u73af\u5883\u53d8\u91cf\u548c Shell \u51fd\u6570\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\n$ set<\/pre>\n<p>\n\t\u4e0b\u9762\u6211\u4eec\u4f1a\u6765\u4e00\u4e00\u7684\u4ecb\u7ecd bash \u811a\u672c\u7684 set \u547d\u4ee4\u7684\u76f8\u5173\u7528\u6cd5\u3002\u5305\u62ecset -u\u3001set -x\u3001Bash \u7684\u9519\u8bef\u5904\u7406\u3001set -e\u3001set -o pipefail\u7b49\u7528\u6cd5\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2337\">Shell bash \u811a\u672c \u7b80\u4ecb<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u670d\u52a1\u5668\u7684\u5f00\u53d1\u548c\u7ba1\u7406\u79bb\u4e0d\u5f00 Bash \u811a\u672c\uff0c\u638c\u63e1\u5b83\u9700\u8981\u5b66\u4e60\u5927\u91cf\u7684\u7ec6\u8282\u3002BASH \u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u811a\u672c\u8bed\u8a00,\u4e0d\u8fc7\u4e3a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118,6],"tags":[706,1130],"class_list":["post-2337","post","type-post","status-publish","format-standard","hentry","category-ndisdevelop","category-yyzt","tag-linux","tag-shell-"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2337"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2337\/revisions"}],"predecessor-version":[{"id":2338,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2337\/revisions\/2338"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}