{"id":1023,"date":"2021-08-07T12:57:28","date_gmt":"2021-08-07T04:57:28","guid":{"rendered":"https:\/\/blog.humh.cn\/?p=1023"},"modified":"2021-08-07T19:46:16","modified_gmt":"2021-08-07T11:46:16","slug":"%e5%85%b3%e4%ba%8eshell%e4%b8%ad%e5%9c%a8%e5%86%85exit%e4%bd%bf%e7%94%a8%e9%97%ae%e9%a2%98%ef%bc%81","status":"publish","type":"post","link":"https:\/\/blog.humh.cn\/?p=1023","title":{"rendered":"\u5173\u4e8eshell\u4e2d\u5728()\u5185exit\u4f7f\u7528\u95ee\u9898\uff01"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>woc\uff0c\u771f\u624d\u77e5\u9053exit\u5728()\u62ec\u53f7\u5185\u4f7f\u7528\uff0c\u5e76\u4e0d\u80fd\u9000\u51fa\u6574\u4e2ashell\u811a\u672c\uff01<\/p><\/blockquote>\n\n\n\n<p>\u6628\u5929\uff0c\u5728\u7ed9\u516c\u53f8\u9879\u76ee\u5199\u4e00\u4e2a\u811a\u672c\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u4e00\u76f4\u7528\u9519\u4e86\u59ff\u52bf\u3002\u3002<\/p>\n\n\n\n<p>\u5982\u4e0b\u6709\u8fd9\u4e48\u4e00\u4e2a\u5927\u81f4\u811a\u672c\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/usr\/bin\/env bash\n\nls \/test || (echo 'dir not exists' &amp;&amp; exit 1)\n# \u5982\u679c\u4e0a\u4e00\u6b65\u6210\u529f\u4e86\uff0c\u8fdb\u884c\u4e0b\u9762\u6b63\u5e38\u7684\u903b\u8f91\nls \/<\/pre>\n\n\n\n<p>\u6211\u5e0c\u671b\uff0c\u5982\u679c<code>ls \/test<\/code>\u6709\u95ee\u9898\uff0c\u53d1\u73b0\u76ee\u5f55\u4e0d\u5b58\u5728\uff0c\u5219\u8f93\u51fa\u63d0\u793a\u4fe1\u606f\uff0c\u5e76\u76f4\u63a5\u9000\u51fa\u811a\u672c\uff0c\u4e0d\u518d\u6267\u884c\u4e4b\u540e\u7684\u903b\u8f91\u3002\u6211\u60f3\u7740\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u548c\u9000\u51fa\u811a\u672c\u662f\u4e00\u4e2a\u903b\u8f91\uff0c\u6240\u4ee5\u62ec\u53f7\u62ec\u8d77\u6765\u3002<\/p>\n\n\n\n<p>\u6267\u884c\u4e0a\u9762\u811a\u672c<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">root@LAPTOP-RPOAPQVQ:\/tmp# .\/test.sh\nls: cannot access '\/test': No such file or directory\ndir not exists\nbin  boot  dev  etc  home  init  lib  lib32  lib64  libx32  lost+found  media  mnt  opt  proc  root  run  sbin  snap  srv  sys  tmp  usr  var<\/pre>\n\n\n\n<p> \u4f46\u771f\u6b63\u7684\u6267\u884c\u6548\u679c\uff0c\u5e76\u6ca1\u6709\u9000\u51fa\u811a\u672c\uff0c\u800c\u662f\u6267\u884c\u4e86\u4e4b\u540e\u7684\u903b\u8f91<code>ls \/<\/code>\u3002\u767e\u601d\u4e0d\u5f97\u5176\u89e3\uff0c\u4e8e\u662f\u5ea6\u5a18\u4e00\u4e0b\uff0c\u624d\u77e5\u9053\u3002<strong>\u539f\u6765exit\u5728\u62ec\u53f7\u5185\u4f7f\u7528\uff0c\u5c31\u53ea\u662f\u9000\u51fa\u62ec\u53f7\u800c\u5df2\uff0c<code>()<\/code>\u5185\u7684shell\u4f1a\u4f5c\u4e3a\u6574\u4e2ashell\u811a\u672c\u7684\u5b50shell\u6267\u884c\uff0c\u800c\u4e0d\u5728\u6574\u4e2ashell\u811a\u672c\u8fdb\u7a0b\u4e2d\uff0c\u6240\u4ee5exit\u53ea\u662f\u9000\u51fa\u4e86\u5b50shell\uff0c\u6240\u4ee5shell\u811a\u672c\u7ee7\u7eed\u6267\u884c\u3002<\/strong>\u5e73\u5e38\uff0c\u6211\u4eec\u6ca1\u6709\u5728\u62ec\u53f7\u5185\u4e9bexit\uff0c\u800c\u5728\u51fd\u6570\u4f53\u6216\u6761\u4ef6\u8bed\u53e5\u4e2d\u8c03\u7528exit\u90fd\u662f\u6ca1\u95ee\u9898\uff0c\u76f4\u63a5\u9000\u51fa\u811a\u672c\u8fdb\u7a0b\u7684\u3002\u56e0\u4e3a\u4ed6\u4eec\u90fd\u4e0d\u4f1a\u5b58\u5728\u5b50shell\u4e2d\u6267\u884c\u7684\u95ee\u9898\u3002\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/usr\/bin\/env bash\n\ntest_fun() {\n    echo 'fun' &amp;&amp; exit 1\n}\n\ntest_fun\n# \u5982\u679c\u4e0a\u4e00\u6b65\u6210\u529f\u4e86\uff0c\u8fdb\u884c\u4e0b\u9762\u6b63\u5e38\u7684\u903b\u8f91\nls \/<\/pre>\n\n\n\n<p>\u6267\u884c\u7ed3\u679c<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">root@LAPTOP-RPOAPQVQ:\/tmp# .\/test.sh\nfun<\/pre>\n\n\n\n<p>\u6240\u4ee5\u9488\u5bf9\u4e0a\u9762\u62ec\u53f7\u5185exit\u7684\u95ee\u9898\uff0c\u811a\u672c\u903b\u8f91\u4e0d\u53d8\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u6539\u4e3a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/usr\/bin\/env bash\n\nls \/test || echo 'dir not exists' &amp;&amp; exit 1\n# \u5982\u679c\u4e0a\u4e00\u6b65\u6210\u529f\u4e86\uff0c\u8fdb\u884c\u4e0b\u9762\u6b63\u5e38\u7684\u903b\u8f91\nls \/<\/pre>\n\n\n\n<p>\u5373\u53bb\u6389<code>()<\/code>\u3002\u6216\u8005\u7528<code>{}<\/code>\u66ff\u4ee3<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/usr\/bin\/env bash\n\nls \/test || { echo 'dir not exists' &amp;&amp; exit 1; }\n# \u5982\u679c\u4e0a\u4e00\u6b65\u6210\u529f\u4e86\uff0c\u8fdb\u884c\u4e0b\u9762\u6b63\u5e38\u7684\u903b\u8f91\nls \/<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>woc\uff0c\u771f\u624d\u77e5\u9053exit\u5728()\u62ec\u53f7\u5185\u4f7f\u7528\uff0c\u5e76\u4e0d\u80fd\u9000\u51fa\u6574\u4e2ashell\u811a\u672c\uff01 \u6628\u5929\uff0c\u5728\u7ed9\u516c\u53f8\u9879\u76ee\u5199\u4e00\u4e2a\u811a\u672c\u7684\u65f6\u5019\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1025,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[53],"tags":[31,104],"_links":{"self":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1023"}],"collection":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1023"}],"version-history":[{"count":1,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1023\/revisions"}],"predecessor-version":[{"id":1024,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1023\/revisions\/1024"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/media\/1025"}],"wp:attachment":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}